FireWall: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Zeile 23: | Zeile 23: | ||
* iptables-Regeln: | * iptables-Regeln: | ||
<pre> | <pre> | ||
# Alles löschen | |||
iptables -F | |||
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE | ||
iptables -A FORWARD -i wlan0 -j ACCEPT | iptables -A FORWARD -i wlan0 -j ACCEPT | ||
</pre> | |||
* Persistente Regeln: | |||
<pre>apt install netfilter-persistent | |||
</pre> | |||
* Regeln in /etc/iptables/rules.v4 | |||
<pre> | |||
raw | |||
:PREROUTING ACCEPT [0:0] | |||
:OUTPUT ACCEPT [0:0] | |||
COMMIT | |||
*filter | |||
:INPUT ACCEPT [0:0] | |||
:FORWARD ACCEPT [0:0] | |||
:OUTPUT ACCEPT [0:0] | |||
COMMIT | |||
*nat | |||
:PREROUTING ACCEPT [0:0] | |||
:INPUT ACCEPT [0:0] | |||
:OUTPUT ACCEPT [0:0] | |||
:POSTROUTING ACCEPT [0:0] | |||
-A PREROUTING -i eno1 -p tcp --dport 11222 -j DNAT --to-destination 10.10.10.102:22 | |||
-A PREROUTING -i eno1 -p tcp --dport 12189 -j DNAT --to-destination 10.10.20.101:3389 | |||
-A POSTROUTING -s 10.10.10.0/24 -o eno1 -j MASQUERADE | |||
-A POSTROUTING -s 10.10.20.0/24 -o eno1 -j MASQUERADE | |||
COMMIT | |||
*mangle | |||
:PREROUTING ACCEPT [0:0] | |||
:INPUT ACCEPT [0:0] | |||
:FORWARD ACCEPT [0:0] | |||
:OUTPUT ACCEPT [0:0] | |||
:POSTROUTING ACCEPT [0:0] | |||
# DHCP packets sent to VMs have no checksum (due to a longstanding bug). | |||
-A POSTROUTING -o virbr1 -p udp -m udp --dport 68 -j CHECKSUM --checksum-fill | |||
-A POSTROUTING -o eno1 -p udp -m udp --dport 68 -j CHECKSUM --checksum-fill | |||
COMMIT | |||
</pre> | </pre> | ||
Version vom 26. Mai 2022, 06:26 Uhr
Links
Info
# relevante IFs: ip -4 addr show scope global # relevante Route ip route show | grep default
Paketweiterleitung
- im Kernel freischalten:
echo 1 > /proc/sys/net/ipv4/ip_forward # Pruefen: cat/proc/sys/net/ipv4/ip_forward sysctl net.ipv4.ip_forward vi /etc/sysctl.conf #net.ipv4.ip_forward=1
- iptables-Regeln:
# Alles löschen iptables -F iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE iptables -A FORWARD -i wlan0 -j ACCEPT
- Persistente Regeln:
apt install netfilter-persistent
- Regeln in /etc/iptables/rules.v4
raw :PREROUTING ACCEPT [0:0] :OUTPUT ACCEPT [0:0] COMMIT *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] COMMIT *nat :PREROUTING ACCEPT [0:0] :INPUT ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] -A PREROUTING -i eno1 -p tcp --dport 11222 -j DNAT --to-destination 10.10.10.102:22 -A PREROUTING -i eno1 -p tcp --dport 12189 -j DNAT --to-destination 10.10.20.101:3389 -A POSTROUTING -s 10.10.10.0/24 -o eno1 -j MASQUERADE -A POSTROUTING -s 10.10.20.0/24 -o eno1 -j MASQUERADE COMMIT *mangle :PREROUTING ACCEPT [0:0] :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] :POSTROUTING ACCEPT [0:0] # DHCP packets sent to VMs have no checksum (due to a longstanding bug). -A POSTROUTING -o virbr1 -p udp -m udp --dport 68 -j CHECKSUM --checksum-fill -A POSTROUTING -o eno1 -p udp -m udp --dport 68 -j CHECKSUM --checksum-fill COMMIT
Internet-Weiterleitung
Es gibt einen Accesspoint 10.0.0.17, der das Netz 10.0.0.0 über WLAN versorgt und per Firewall illegale Aktionen verhindern soll. Im Beispiel gibt es den Host 10.0.100.1, der in diesem abgeschotteten Netz liegt.
Der Accesspoint hat die 2te Adresse 192.168.178.17, das über das Gateway 192.168.178.3 Zugriff aufs Internet hat.
------------- ------------------ | 10.0.100.1 |--------- | 10.0.0.17 | ----------------- | vbox | | dream | | 192.168.178.3 | -------------- | 192.168.178.17 |----------| fritzbox |---------- Internet ------------------ -----------------
- In der Fritzbox ist eine statische Route einzutragen, sonst kommen die Antworten Auf Anfragen von vbox nicht an:
- route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.178.17
- vbox braucht eine Route ins internet:
route add -net 192.168.178.0 netmask 255.255.255.0 gw 10.0.0.17 eth0 route add default gw 10.0.0.17 eth0
- Für DNS ist die Fritzbox zuständig: /etc/resolv.conf
nameserver 192.168.178.3