Gateway mit Openwrt: Unterschied zwischen den Versionen

Aus Freifunk Franken
Wechseln zu:Navigation, Suche
Zeile 1: Zeile 1:
= Gateway mit OpenWrt einrichten =
= OpenWrt einrichten =


Eine Anleitung, ein dezentrales/lokales Gateway mit OpenWrt einzurichten.
Eine Anleitung, ein dezentrales/lokales Gateway mit OpenWrt einzurichten.

Version vom 10. März 2019, 22:14 Uhr

OpenWrt einrichten

Eine Anleitung, ein dezentrales/lokales Gateway mit OpenWrt einzurichten.

Hier am Beispiel eines TP-Link Archer C2600.

Der Router wird dezentrales Gateway.

Wir können viel aus der Anleitung Freifunk-Gateway aufsetzen ableiten.

Grundinstallation

  • Als erstes ein aktuelles OpenWrt flashen.
  • Am Webinterface anmelden und ein Rootpasswort vergeben. Eventuell ssh an allen Devices erlauben, macht es leichter drauf zu kommen, während wir konfigurieren. Man kann auch gleich seinen ssh-key hinterlegen.
  • Hostname festlegen und Zeitzone setzen.

Jetzt sollte man sich via ssh am Router einloggen können.

Firewall

Erst mal ausschalten. Kann Probleme beim Testen und Konfigurieren machen.

/etc/init.d/firewall stop
/etc/init.d/firewall disable


Routingtabelle deklarieren

Tabellennummer und Name in /etc/iproute2/rt_tables eintragen.

10     fff

Vorbereitung zur Installation der Pakete

Es können nur Pakete via Internet installiert werden, wenn zuvor die Paketquellen, die in /etc/opkg definiert sind, aktualisiert werden.

opkg update

Konfiguration

opkg install ip-bridge ip-full iptables ip6tables
auch hilfreich
opkg install tcpdump iperf3

Netzwerkinterfaces

Die Konfiguration der Interfaces, das Routing und des Switches erfolgt in /etc/config/network und die Wifi-Interfaces in /etc/config/wireless

Hier ein Beispiel mit dem TP-Link Archer C2600.

  • Die /etc/config/wireless
config wifi-device 'radio0'
	option type 'mac80211'
	option hwmode '11a'
	option path 'soc/1b500000.pci/pci0000:00/0000:00:00.0/0000:01:00.0'
	option country 'DE'
	option legacy_rates '1'
	option disabled '0'
	option channel '40'
	option htmode 'VHT40'
	option txpower '16'

config wifi-iface 'w5ap'
	option device 'radio0'
	option ifname 'w5ap'
	option mode 'ap'
	option ssid 'freifunk.xxx.net'
	option encryption 'none'
	option hidden '0'
	option network 'mesh'

config wifi-device 'radio1'
	option type 'mac80211'
	option hwmode '11g'
	option path 'soc/1b700000.pci/pci0001:00/0001:00:00.0/0001:01:00.0'
	option htmode 'HT20'
	option country 'DE'
	option legacy_rates '1'
	option disabled '0'
	option channel '13'
	option txpower '16'

config wifi-iface 'w2ap'
	option device 'radio1'
	option ifname 'w2ap'
	option mode 'ap'
	option ssid 'freifunk.xxx.net'
	option encryption 'none'
	option hidden '0'
	option network 'mesh'
  • Die /etc/config/Network; hier die Grundkonfiguration
config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config globals 'globals'
	option ula_prefix 'fdff:0::/64'

config interface 'lan'    
#### mit dem Interface haengt man im Home-LAN. In die Bridge kann man dann
#### einfach ein wireless Interface hängen und das Heimnetz ausstrahlen.
	option type 'bridge'
	option proto 'static'
	option ipaddr 'local IP'  ### meistens 192.168.xxx.xxx
	option netmask '255.255.255.0'
	option ip6assign '64'
	option gateway 'local default route'
	option dns 'x.x.x.x 9.9.9.9'
	option ifname 'eth1.1'

# oder einfach DHCP
# config interface 'lan'
#        option proto 'dhcp'

config interface 'mesh'
	option type 'bridge'
	option macaddr 'ec:08:6b:xx:xx:xx'
	option proto 'static'
	option ipaddr 'your fff IP'
	option netmask '255.255.255.xxx'
	option broadcast '10.83.xx.255'
	list ip6addr 'fd43:5602:29bd:your fff IP/64'
	list ip6addr 'fe80::1/64'
	option ip4table 'fff'
	option ip6table 'fff'
	option ifname 'eth0.2'

config interface 'lan6'
	option proto 'dhcpv6'
	option ifname 'eth1.1'
	option reqaddress 'try'
	option reqprefix 'auto'
  • Die Switchkonfiguration
config switch
	option name 'switch0'
	option reset '1'
	option enable_vlan '1'

config switch_vlan
	option device 'switch0'
	option vlan '1'
	option vid '1'
	option ports '5 6t' ### Hier den Uplink anstecken

config switch_vlan
	option device 'switch0'
	option vlan '2'
	option ports '1 2 3 4 0t'  ### auf den Ports faellt das fff-Netz raus
	option vid '2'

Anbindung ans Freifunknetz

WireGuard

Wir brauchen eine Anbindung an das Freifunknetz. Dafür eignet sich WireGuard oder eine Richtfunkstrecke oder ein Kabel o.ä. Dazu mit Peeringpartner absprechen.

  • WireGuard installieren
opkg install wireguard
  • Die Konfiguration erfolgt auch in /etc/config/Network.

Man benötigt einen Peeringpartner im Freifunknetz, zu dem man einen WireGuard-Tunnel aufbauen kann. Dazu auf der Mailingliste anfragen, oder man kennt schon jemanden persönlich. Da tauscht man dann die Keys aus.


config interface 'fff'
	option proto 'wireguard'
	option listen_port '31337'
	list addresses '10.83.252.xx/32'
	list addresses 'fe80::babe:xx:xx/64'
	list addresses 'fd43:5602:29bd:ffff::xx'
	option private_key 'Der ist auch geheim'

config wireguard_fff
	option ifname 'fff'
	option public_key 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx='
	option allowed_ips '0.0.0.0/0 ::/0'
	option endpoint_host 'yor peering partner IP'
	option endpoint_port '31337'
	option persistent_keepalive '60'

Richtfunk

Babel

Damit das Routing funktioniert brauchen wir noch Babel.

  • Installieren
opkg install babeld
  • Konfiguration in /etc/config/babeld
config general
	option export_table '10'
	option import_table '10'
	option first_table_number '100'
	option local_port '33123'


config interface
	option type 'wired'

config interface 'fff'
	option ifname 'fff'
	option type 'wired'

config filter
	option type 'redistribute'
	option local 'true'
	option ip '10.0.0.0/8'

config filter
	option type 'redistribute'
	option local 'true'
	option ip 'fd43:5602:29bd::/48'

config filter
	option type 'redistribute'
	option local 'true'
	option action 'deny'

config filter
	option type 'redistribute'
	option ip '10.0.0.0/8'

config filter
	option type 'redistribute'
	option ip 'fd43:5602:29bd::/48'

Routing

Das Routing wird auch in der /etc/config/network eingetragen.

config rule
	option in 'mesh'
	option dest '0.0.0.0/0'
	option lookup 'fff'

config rule
	option in 'fff'
	option dest '0.0.0.0/0'
	option lookup 'fff'

config rule
	option dest '10.0.0.0/8'
	option lookup 'fff'

config rule6
	option in 'mesh'
	option dest '::/0'
	option lookup 'fff'

config rule6
	option in 'fff'
	option dest '::/0'
	option lookup 'fff'

config rule6
	option dest 'fc00::/7'
	option lookup 'fff'

config rule6
	option src 'fc00::/7'
	option lookup 'fff'


config route 'fffclient'
	option interface 'mesh'
	option target '10.83.xx.0'
	option netmask '255.255.255.192'
	option table 'fff'

config route6 'ffffd43'
	option interface 'mesh'
	option target 'fd43:5602:29bd:xx::/64'
	option table 'fff'
  • TCP clamping

Bis die Firewall fertig ist, kommt das erst mal in die /etc/rc.local.

# clamping
iptables -t mangle -A POSTROUTING -p tcp --tcp-flags SYN,RST SYN -o fff -j TCPMSS --clamp-mss-to-pmtu

Hood

dhcp und Nameserver

  • Konfiguration von dnsmasq in /etc/config/dhcp
config dnsmasq
        option domainneeded '0'
        option boguspriv '0'   
        option filterwin2k '0'
        option localise_queries '0'
        option rebind_protection '0'
        option rebind_localhost '1' 
        option domain 'fff.community'
        option expandhosts '0'       
        option nonegcache '0' 
        option authoritative '1'
        option readethers '1'   
        option leasefile '/tmp/dhcp.leases'
        option resolvfile '/tmp/resolv.conf.auto'
        option nonwildcard '1'                   
        option localservice '0'
        list server '10.50.252.0'
        list server '/in-addr.arpa/10.50.252.0'
        list server '/ip6.arpa/10.50.252.0'    
                                               
config dhcp 'mesh'                         
        option leasetime '12h'
        option interface 'mesh'
        option start '11'      
        option limit '52'      
        list dhcp_option '6,10.50.252.0'
        option ra 'server'              
        option ra_management '0'        
        option ra_default '0'           
                                
config odhcpd 'odhcpd'          
        option maindhcp '0'  
        option leasefile '/tmp/hosts/odhcpd'
        option leasetrigger '/usr/sbin/odhcpd-update'
        option loglevel '4'                          

Batman

  • Kernelmodul und batctl installieren
opkg install kmod-batman-adv
opkg install batctl
  • Batman konfigurieren in /etc/config/batman
config mesh 'bat0'
        option gw_mode 'server'
        option bridge_loop_avoidance '0'
        option network_coding '0'
        option aggregated_ogms '1'
        option ap_isolation '0'
        option bonding '0'
        option fragmentation '1'
        option orig_interval '1000'
        option distributed_arp_table '1'
        option hop_penalty '30'

Interfaces, wifi und switch

  • bat0 in die Bridge mesh stecken. (/etc/config/network)
config interface 'mesh'
	option ifname 'bat0 eth0.1'  # hier bat0 hinzufügen
  • Interfaces ins bat0. (/etc/config/network)
config interface 'ethmesh'
	option mtu '1528'
	option proto 'batadv'
	option mesh 'bat0'
	option ifname 'eth0.3'
	option macaddr 'ec:08:6b:27:02:cd'

config interface 'w2mesh'
	option mtu '1528'
	option proto 'batadv'
	option mesh 'bat0'
  • Switch konfigurieren. ethmesh auf eth0.3 kommt auf Port 1 raus.
config switch_vlan 'eth0_3'
	option device 'switch0'
	option vlan '3'
	option vid '3'
	option ports '0t 1'

## vlan 1 ändern
config switch_vlan
	option device 'switch0'
	option vlan '1'
	option vid '1'
	option ports '2 3 4 6t'  ### hier Port 1 weg nehmen
  • Wifi w2mesh und w2configap hinzufügen (?etc/config/wireless)
config wifi-iface 'w2mesh'
	option device 'radio1'
	option network 'w2mesh'
	option ifname 'w2mesh'
	option mode 'mesh'
	option mesh_id 'mesh.mainberg.freifunk.net'
	option encryption 'none'
	option mesh_fwding '0'

config wifi-iface 'w2configap'
	option device 'radio1'
	option network 'configap2'
	option ifname 'w2configap'
	option mode 'ap'
	option ssid 'config.franken.freifunk.net'
	option encryption 'none'
	option hidden '1'


Alfred

  • Installieren
opkg install alfred
  • Konfiguration in /etc/config/alfred
config alfred 'alfred'
        option interface 'br-mesh'
        option mode 'master'
        option batmanif 'none'
        option start_vis '0'
        option run_facters '0'

Alfred Monitoring Proxy

Siehe auch Gatewayanleitung Freifunk-Gateway_aufsetzen/Alfred

Wir benötigen das alfred-json von kratz00 (https://github.com/kratz00/alfred-json). Entweder selbst kompilieren (Achtung! Darauf achten, dass man es für die richtige Plattform Kompiliert) Oder auf der ML fragen, ob schon jemand ein passendes Binary oder ipk hat.

Für den c2600 gibt es hier: http://159.69.26.184/alfred-json_0.0.1-1_arm_cortex-a15_neon-vfpv4.ipk ein ipk zum installieren.

  • Selbst kompilieren

Man besorgt sich die OpenWrt Quellen und bereitet alles vor: https://openwrt.org/docs/guide-developer/quickstart-build-images

Das Makefile nach package/utils/alfred-json/Makefile


include $(TOPDIR)/rules.mk

PKG_NAME:=alfred-json
PKG_VERSION:=0.0.1
PKG_RELEASE:=1
PKG_LICENSE:=GPL-2.0
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=e4cacfc791092389f63c36a435d3f1d069f8a13e
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_URL:=https://github.com/kratz00/alfred-json.git

include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/cmake.mk

define Package/alfred-json
        SECTION:=utils
        CATEGORY:=Utilities
        TITLE:= A.L.F.R.E.D - JSON Client
        URL:=https://github.com/kratz00/alfred-json
        DEPENDS:=+jansson +zlib
endef

define Package/alfred-json/install
        $(INSTALL_DIR) $(1)/bin/
        $(CP) $(PKG_INSTALL_DIR)/usr/bin/alfred-json $(1)/bin/
endef

$(eval $(call BuildPackage,alfred-json))

Jetzt make menuconfig und target auswählen und unter utils findet man alfred-json. Das Package als Modul anwählen <M>

make package/utils/alfred-json/{clean,compile}

baut das ipkg. Es sollte unter bin/packages/Targetxxxx/alfred-json.xxxx.ipkg zu finden sein und kann mit opkg installiert werden.

  • Skript anlegen
cat /usr/sbin/alfred-monitoring-proxy 
#!/bin/ash

api_url="http://monitoring.freifunk-franken.de/api/alfred"

fetch_ids="64"

for fetch_id in $fetch_ids
do
    data=$(alfred-json -r "$fetch_id")
    curl -k -v -H "Content-type: application/json; charset=UTF-8" -X POST --data "{\"$fetch_id\": $data}" $api_url
done

  • cronjob anlegen
crontab -e
*/5 * * * * sleep 70; /usr/sbin/alfred-monitoring-proxy

Hoodfile und Webserver zum Ausliefern

  • Webserver Konfig ergänzen in /etc/config/uhttpd
config uhttpd 'hood'
        list listen_http '2342'
        option home '/www/hood'
        option rfc1918_filter '1'
        option network_timeout '30'
        option tcp_keepalive '1'
        option config '_'
  • Das Hoodfile nach /www/hood/keyxchangev2data legen

Beispiel

{
  "hood": {
    "ntp_ip": "fd43:5602:29bd:ffff::10",
    "name": "Myhood",
    "mesh_type2": "802.11s",
    "mesh_essid": "mesh.myhood.freifunk.net",
    "mesh_bssid": "",
    "mesh_type5": "802.11s",
    "mode5": "ht20",
    "essid": "freifunk.myhood.net",
    "channel5": "40",
    "upgrade_path": "",
    "timestamp": "1516486388",
    "channel2": "13",
    "protocol": "batman-adv-v15",
    "mesh_id": "mesh.myhood.freifunk.net",
    "mode2": "ht20"
  },
  "network": {
    "ula_prefix": "fd43:5602:29bd:xx:/64"
  },
  "version": 1
}

Besonderheit TP-Link Archer C2600

Mit dem Standard Wifimodul und Wifi-Firmware kann der Archer C2600 kein Mesh. Falls man Mesh braucht, muss man diese austauschen. Die funktionierenden sind auch im OpenWrt Repo.


opkg remove ath10k-firmware-qca4019 
opkg install kmod-ath10k-ct ath10k-firmware-qca99x0-ct