Gateway mit Openwrt: Unterschied zwischen den Versionen

Aus Freifunk Franken
Wechseln zu:Navigation, Suche
Zeile 486: Zeile 486:
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.  
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://88.99.168.88/alfred-json_0.0.1-1_arm_cortex-a15_neon-vfpv4.ipk ein ipk zum installieren.
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.


* Skript anlegen
* Skript anlegen

Version vom 21. Dezember 2018, 12:48 Uhr

Gateway mit OpenWrt einrichten

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

Hier am Beispiel eines TP-Link c2600.

Der Router wird Gateway für eine Dezentrale Hood.

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. Ev. 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, Zeitzone

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

Konfiguration

opkg install ip-bridge ip-full iptables ip6tables ebtables ebtables-utils
auch hilfreich
opkg install tcpdump 

Netzwerkinterfaces

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

Hier ein Beispiel mit Freifunk und Heimnetz auf dem c2600. Freifunk hier nur auf 2,4GHz.

  • 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 'w5home'
	option device 'radio0'
	option mode 'ap'
	option encryption 'psk2'
	option ifname 'w5home'
	option network 'lan'
	option ssid 'Homenetz5'
	option key 'xxxxxxxxxxxxxxx'

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 'w2home'
	option device 'radio1'
	option mode 'ap'
	option encryption 'psk2'
	option ifname 'w2home'
	option network 'lan'
	option ssid 'Homenetz2'
	option key 'xxxxxxxxxxx'

config wifi-iface 'w2ap'
	option device 'radio1'
	option ifname 'w2ap'
	option mode 'ap'
	option ssid 'freifunk.mainberg.net'
	option encryption 'none'
	option hidden '0'
	option network 'mesh'

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'
  • 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'
	option type 'bridge'
	option proto 'static'
	option ipaddr '192.168.100.66'
	option netmask '255.255.255.0'
	option ip6assign '64'
	option gateway '192.168.100.1'
	option dns '192.168.100.1 9.9.9.9'
	option ifname 'eth1.1'

config interface 'mesh'
	option type 'bridge'
	option macaddr 'ec:08:6b:27:02:cb'
	option proto 'static'
	option ipaddr '10.83.85.1'
	option netmask '255.255.255.192'
	option broadcast '10.83.85.255'
	list ip6addr 'fd43:5602:29bd:27::1/64'
	list ip6addr 'fe80::1/64'
	option ifname 'bat0 eth0.1'

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'

config interface 'wan6'
	option proto 'dhcpv6'
	option ifname 'eth1.1'
	option reqaddress 'try'
	option reqprefix 'auto'

config interface 'configap2'
	option proto 'static'
	option ip6addr 'fe80::1/64'

  • Die Switchkonfiguration (Hier hängen alle Ports an vlan1, da ich den im Moment "nur" als Switch im Heimnetz nutze)
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 '1 2 3 4 5 6t'

config switch_vlan
	option device 'switch0'
	option vlan '2'
	option ports '0t'
	option vid '2'

config switch_vlan 'eth0_3'
	option device 'switch0'
	option vlan '3'
	option vid '3'
	option ports '0t'

Batman-adv

  • 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'
  • Das Batman device hängt in der Bridge mesh, die oben schon konfiguriert ist.

Wireguard

Wir brauchen eine Anbindung an das Freifunknetz. Dafür eignet sich Wireguard hervorragend.

  • Wireguard installieren
opkg install wireguard
  • Die konfiguration erfolgt auch in /etc/config/network

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

In dieser Beispielkonfiguration gibt es noch einen Wireguardtunnel nach Schweden zu azire-vpn, über den der Internettraffic raus geht.


config interface 'wg0'
	option proto 'wireguard'
	option private_key 'Der ist geheim'
	option listen_port '51820'
	list addresses '10.10.27.44/19'

config wireguard_wg0
	option ifname 'wg0'
	option public_key 'T28Qn5VFzT4wiwEPd7DscwcP3Rsmq23QcnjH1N5G/wc='
	list allowed_ips '0.0.0.0/0 ::/0'
	option endpoint_host 'se1.wg.azirevpn.net'
	option endpoint_port '51820'
	option persistent_keepalive '25'

config interface 'fff'
	option proto 'wireguard'
	option listen_port '31337'
	list addresses '10.83.252.10/32'
	list addresses 'fe80::babe:66:10/64'
	list addresses 'fd43:5602:29bd:ffff::17'
	option private_key 'Der ist auch geheim'

config wireguard_fff
	option ifname 'fff'
	option public_key 'cG9uIgQqVf9BCxHtAeaVBxnvyc5iHpoHoh82h9dv63w='
	option allowed_ips '0.0.0.0/0 ::/0'
	option endpoint_host '88.99.168.88'
	option endpoint_port '31337'
	option persistent_keepalive '60'

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 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 ip '2a0b:f4c0::/32'

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'

config filter
	option type 'redistribute'
	option ip '2a0b:f4c0::/32'

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

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 in 'wg0'
	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 'wg0'
	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 'fffdefault'
	option interface 'wg0'
	option target '0.0.0.0'
	option netmask '0.0.0.0'
	option gateway '10.10.0.1'
	option table 'fff'

config route 'hood'
	option interface 'mesh'
	option target '10.83.85.0'
	option netmask '255.255.255.192'
	option table 'fff'

config route6 'fffdefault6'
	option interface 'wg0'
	option target '::/0'
	option gateway '2a03:8600:1001:4000::1'
	option table 'fff'

config route6 'hood6'
	option interface 'mesh'
	option target '2a03:8600:1001:5b2a::/64'
	option table 'fff'

config route6 'hoodfd43'
	option interface 'mesh'
	option target 'fd43:5602:29bd:27::/64'
	option table 'fff'

  • TCP clamping und, falls man selbst Internet ausleitet, Masquerading

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 wg0 -j TCPMSS --clamp-mss-to-pmtu
iptables -t mangle -A POSTROUTING -p tcp --tcp-flags SYN,RST SYN -o fff -j TCPMSS --clamp-mss-to-pmtu

# Masquerade vpn
iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE

dhcp und Nameserver

  • Konfiguration von dnsmasq in /etc/config/dhcp
config dnsmasq
	option domainneeded '1'
	option boguspriv '1'
	option filterwin2k '0'
	option localise_queries '1'
	option rebind_protection '1'
	option rebind_localhost '1'
	option local '/lan/'
	option domain 'lan'
	option expandhosts '1'
	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 '1'

config odhcpd 'odhcpd'
	option maindhcp '0'
	option leasefile '/tmp/hosts/odhcpd'
	option leasetrigger '/usr/sbin/odhcpd-update'
	option loglevel '4'

config dhcp 'mesh'
	option leasetime '12h'
	option interface 'mesh'
	option start '11'
	option limit '52'
	option ra 'server'

config dhcp 'lan'
	option interface 'lan'
	option ignore '1'

config dhcp 'wan'
	option interface 'wan'
	option ignore '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.

  • 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": "Mainberg",
    "mesh_type2": "802.11s",
    "mesh_essid": "mesh.mainberg.freifunk.net",
    "mesh_bssid": "",
    "mesh_type5": "802.11s",
    "mode5": "ht20",
    "essid": "freifunk.mainberg.net",
    "channel5": "40",
    "upgrade_path": "",
    "timestamp": "1516486388",
    "channel2": "13",
    "protocol": "batman-adv-v15",
    "mesh_id": "mesh.mainberg.freifunk.net",
    "mode2": "ht20"
  },
  "network": {
    "ula_prefix": "fd43:5602:29bd:27:/64"
  },
  "version": 1
}


Besonderheit TP c2600

Mit dem Standard wifimodul und wifi-Firmware kann der c2600 kein mesh. Wir müssen diese austauschen. Die funktionierenden sind auch im OpenWrt Repo.


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