Firewall-Nat-Linux - Netzwerk und Serveradministration: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
| (5 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
| Zeile 3: | Zeile 3: | ||
*Y = Klassensaal | *Y = Klassensaal | ||
=Hostname= | =Hostname= | ||
| − | *hostnamectl set-hostname fw. | + | *hostnamectl set-hostname fw.it2XX.int |
=Interfaces= | =Interfaces= | ||
| Zeile 18: | Zeile 18: | ||
auto enp0s3 | auto enp0s3 | ||
iface enp0s3 inet static | iface enp0s3 inet static | ||
| − | address 192.168. | + | address 192.168.Y.2XX/24 |
| − | gateway 192.168. | + | gateway 192.168.Y.254 |
post-up ip route add 10.88.0.0/16 via 192.168.Y.88 | post-up ip route add 10.88.0.0/16 via 192.168.Y.88 | ||
| − | + | ||
#LAN | #LAN | ||
auto enp0s8 | auto enp0s8 | ||
iface enp0s8 inet static | iface enp0s8 inet static | ||
| − | address 172.16. | + | address 172.16.2XX.1/24 |
#DMZ | #DMZ | ||
auto enp0s9 | auto enp0s9 | ||
iface enp0s9 inet static | iface enp0s9 inet static | ||
| − | address 10.88. | + | address 10.88.2XX.1/24 |
#SERVERS | #SERVERS | ||
auto enp0s10 | auto enp0s10 | ||
iface enp0s10 inet static | iface enp0s10 inet static | ||
| − | address 10. | + | address 10.2XX.1.1/24 |
</pre> | </pre> | ||
| Zeile 42: | Zeile 42: | ||
*cat /etc/hosts | *cat /etc/hosts | ||
<pre> | <pre> | ||
| − | 127.0.0.1 | + | 127.0.0.1 localhost |
| − | 127.0.1.1 | + | 127.0.1.1 fw.it2XX.int fw |
# The following lines are desirable for IPv6 capable hosts | # The following lines are desirable for IPv6 capable hosts | ||
| − | ::1 | + | ::1 localhost ip6-localhost ip6-loopback |
ff02::1 ip6-allnodes | ff02::1 ip6-allnodes | ||
ff02::2 ip6-allrouters | ff02::2 ip6-allrouters | ||
| Zeile 52: | Zeile 52: | ||
=Resolver= | =Resolver= | ||
*cat /etc/resolv.conf | *cat /etc/resolv.conf | ||
| − | search | + | search it2XX.int |
nameserver 192.168.Y.88 | nameserver 192.168.Y.88 | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
=NAT mit nftables= | =NAT mit nftables= | ||
| + | ;Datei erstellen, alles was drin ist kann raus | ||
| + | *cat /etc/nftables.conf | ||
<pre> | <pre> | ||
#!/usr/sbin/nft -f | #!/usr/sbin/nft -f | ||
# Variablen | # Variablen | ||
| − | define LAN = 172.16. | + | define LAN = 172.16.2XX.0/24 |
| − | define SERVERS = 10. | + | define SERVERS = 10.2XX.1.0/24 |
| − | define DMZ = 10.88. | + | define DMZ = 10.88.2XX.0/24 |
# Alte Regeln löschen (flush) | # Alte Regeln löschen (flush) | ||
| Zeile 105: | Zeile 90: | ||
} | } | ||
</pre> | </pre> | ||
| + | ;Firewall aktivieren | ||
| + | *systemctl enable nftables --now | ||
| + | |||
=Forward= | =Forward= | ||
| − | *echo "net.ipv4.ip_forward=1" | + | *echo "net.ipv4.ip_forward=1" > /etc/sysctl.d/99-ipforward.conf |
| − | *sysctl -p | + | *sysctl -p /etc/sysctl.d/99-ipforward.conf |
| + | |||
=Reboot= | =Reboot= | ||
*systemctl reboot | *systemctl reboot | ||
Aktuelle Version vom 27. März 2026, 13:27 Uhr
Erklärung
- XX = Platznummer
- Y = Klassensaal
Hostname
- hostnamectl set-hostname fw.it2XX.int
Interfaces
- cat /etc/network/interfaces
source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface #WAN auto enp0s3 iface enp0s3 inet static address 192.168.Y.2XX/24 gateway 192.168.Y.254 post-up ip route add 10.88.0.0/16 via 192.168.Y.88 #LAN auto enp0s8 iface enp0s8 inet static address 172.16.2XX.1/24 #DMZ auto enp0s9 iface enp0s9 inet static address 10.88.2XX.1/24 #SERVERS auto enp0s10 iface enp0s10 inet static address 10.2XX.1.1/24
Hosts
- cat /etc/hosts
127.0.0.1 localhost 127.0.1.1 fw.it2XX.int fw # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes ff02::2 ip6-allrouters
Resolver
- cat /etc/resolv.conf
search it2XX.int nameserver 192.168.Y.88
NAT mit nftables
- Datei erstellen, alles was drin ist kann raus
- cat /etc/nftables.conf
#!/usr/sbin/nft -f
# Variablen
define LAN = 172.16.2XX.0/24
define SERVERS = 10.2XX.1.0/24
define DMZ = 10.88.2XX.0/24
# Alte Regeln löschen (flush)
flush table ip nat
# NAT-Tabelle erstellen/verwenden
table ip nat {
chain postrouting {
type nat hook postrouting priority 100; policy accept;
# DMZ nach 192.168.Y.0/24 - kein NAT (RETURN)
ip saddr $DMZ ip daddr 192.168.Y.0/24 return
# DMZ nach 10.88.0.0/16 - kein NAT (RETURN)
ip saddr $DMZ ip daddr 10.88.0.0/16 return
# DMZ nach außen (enp0s3) - Masquerade
ip saddr $DMZ oif enp0s3 masquerade
# LAN nach außen - Masquerade
ip saddr $LAN oif enp0s3 masquerade
# SERVERS nach außen - Masquerade
ip saddr $SERVERS oif enp0s3 masquerade
}
}
- Firewall aktivieren
- systemctl enable nftables --now
Forward
- echo "net.ipv4.ip_forward=1" > /etc/sysctl.d/99-ipforward.conf
- sysctl -p /etc/sysctl.d/99-ipforward.conf
Reboot
- systemctl reboot