Blame
|
1 | # Alpine Router |
||||||
| 2 | ||||||||
| 3 | Alpine linux NAT router mit iptables und dnsmasq für privates Netzwerk mit DNS und DHCP. |
|||||||
| 4 | ||||||||
| 5 | Als Basis werden eth0 als WAN und eth1 als LAN1 eingerichtet. |
|||||||
| 6 | ||||||||
| 7 | für |
|||||||
| 8 | ||||||||
| 9 | --------------------Beispiel `/etc/network/interfaces`--------------- |
|||||||
| 10 | ||||||||
| 11 | ``` |
|||||||
| 12 | auto eth0 |
|||||||
| 13 | iface eth0 inet dhcp |
|||||||
| 14 | ||||||||
| 15 | auto eth1 |
|||||||
| 16 | iface eth1 inet static |
|||||||
| 17 | address 192.168.1.2 |
|||||||
| 18 | netmask 255.255.255.0 |
|||||||
| 19 | ||||||||
| 20 | ( auto eth2 |
|||||||
| 21 | iface eth2 inet static |
|||||||
| 22 | ||||||||
| 23 | address 192.168.2.2 |
|||||||
| 24 | ||||||||
| 25 | netmask 255.255.255.0 |
|||||||
| 26 | ||||||||
| 27 | . |
|||||||
| 28 | ||||||||
| 29 | . |
|||||||
| 30 | ||||||||
| 31 | . ) |
|||||||
| 32 | ``` |
|||||||
| 33 | ||||||||
| 34 | --------------------------------------------------------------------- |
|||||||
| 35 | ||||||||
| 36 | ```sh |
|||||||
| 37 | #!/bin/sh |
|||||||
| 38 | # script iptables.sh |
|||||||
| 39 | apk add iptables |
|||||||
| 40 | rc-update add iptables |
|||||||
| 41 | ||||||||
| 42 | echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf |
|||||||
| 43 | ||||||||
| 44 | iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE |
|||||||
| 45 | iptables -A FORWARD -i eth1 -j ACCEPT |
|||||||
| 46 | /etc/init.d/iptables save |
|||||||
| 47 | ||||||||
| 48 | #/sbin/reboot |
|||||||
| 49 | ``` |
|||||||
| 50 | ||||||||
| 51 | --------------------------------------------------------------------- |
|||||||
| 52 | ||||||||
| 53 | ```sh |
|||||||
| 54 | #!/bin/sh |
|||||||
| 55 | # script dnsmasq.sh |
|||||||
| 56 | ||||||||
| 57 | apk add dnsmasq |
|||||||
| 58 | rc-update add dnsmasq |
|||||||
| 59 | ||||||||
| 60 | # interface - interface to listen for DHCP and DNS requests |
|||||||
| 61 | # domain - domain for the private network |
|||||||
| 62 | # dhcp_range - lower bound, upper bound, lease timeout |
|||||||
| 63 | ||||||||
| 64 | interface=eth1 |
|||||||
| 65 | domain=example.com |
|||||||
| 66 | dhcp_range="192.168.1.100,192.168.1.254,12h" |
|||||||
| 67 | ||||||||
| 68 | sed -i \ |
|||||||
| 69 | "s/^#\?\(interface=\).*/\1$interface/; \ |
|||||||
| 70 | s/^#\(listen-address\)=.*/\1=127.0.0.1/; \ |
|||||||
| 71 | s/^#\(expand-hosts\)/\1/; \ |
|||||||
| 72 | s/^#\?\(domain=\)[^,]*$/\1$domain/; \ |
|||||||
| 73 | s/^#\?\(dhcp-range=\)\d\{1,3\}.\d\{1,3\}.\d\{1,3\}.\d\{1,3\},\d\{1,3\}.\d\{1,3\}.\d\{1,3\}.\d\{1,3\},[^,]*$/\1$dhcp_range/" \ |
|||||||
| 74 | /etc/dnsmasq.conf |
|||||||
| 75 | ||||||||
| 76 | #/sbin/reboot |
|||||||
| 77 | ``` |
|||||||
| 78 | ||||||||
| 79 | static ip, nameserver resolf.conf |
|||||||
| 80 | ||||||||
| 81 | add nameserver 8.8.8.8 |
|||||||
| 82 | ||||||||
| 83 | -------------------------------------------------------------------- |
|||||||
| 84 | ||||||||
| 85 | `apk add util-linux` |
|||||||
| 86 | zur Funktionserweiterung von dmesg, sonst kein -T etc. |
|||||||