Ahoj, začínám s iptables. Chci aby mě propouštěli ipsec vpn což funguje a i vše ostatní. Jen nemohu přijít na icmp, ty fungují pořád ikdyž jsou DROP.
Přikládám můj iptables soubor a prosím o kontrolu zda-li je to sekvenčně správně.
Děkuji.
#!/bin/sh
LSMOD="/sbin/lsmod"
MODPROBE="/sbin/modprobe"
IPTABLES="/sbin/iptables"
IP6TABLES="/sbin/ip6tables"
IPTABLES_RESTORE="/sbin/iptables-restore"
IP6TABLES_RESTORE="/sbin/ip6tables-restore"
IP="/sbin/ip"
IFCONFIG="/sbin/ifconfig"
VCONFIG="/sbin/vconfig".
BRCTL="/sbin/brctl"
IFENSLAVE="/sbin/ifenslave"
IPSET="/usr/sbin/ipset"
LOGGER="/usr/bin/logger"
# Define network interfaces
eth0="enp0s3"
# reset_iptables_v4
$IPTABLES -P OUTPUT DROP
$IPTABLES -P INPUT DROP
$IPTABLES -P FORWARD DROP
# reset_iptables_v6
$IP6TABLES -P OUTPUT DROP
$IP6TABLES -P INPUT DROP
$IP6TABLES -P FORWARD DROP
# Allow localhost lo
$IPTABLES -A INPUT -i lo -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -o lo -m state --state NEW -j ACCEPT
# Reject connection attempts not initiated from the host
$IPTABLES -A INPUT -p tcp --syn -j DROP
# Allow return connections initiated from the host
$IPTABLES -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# accept established sessions
$IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Ping request
$IPTABLES -A INPUT -p icmp --icmp-type echo-request -j DROP
$IPTABLES -A INPUT -p icmp --icmp-type time-exceeded -j DROP
$IPTABLES -A INPUT -p icmp --icmp-type destination-unreachable -j DROP
# NAT Rules
# NAT rule for ipsec
$IPTABLES -t nat -A POSTROUTING -s 10.0.0.0/24 -d 192.168.3.4 -m policy --pol ipsec --dir out -j ACCEPT
# NAT masquerade
$IPTABLES -t nat -A POSTROUTING -o $eth0 -s 10.0.0.0/24 -j SNAT --to-source 192.168.3.4
# Anti spoofing rule
$IPTABLES -A INPUT -i $eth0 -s 192.168.3.4 -m state --state NEW -j DROP
$IPTABLES -A FORWARD -i $eth0 -s 192.168.3.4 -m state --state NEW -j DROP
$IPTABLES -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
# SSH access
$IPTABLES -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -j ACCEPT
# Accept IPsec connections rules
$IPTABLES -A INPUT -p udp -m udp --dport 500 -m state --state NEW -j ACCEPT
$IPTABLES -A INPUT -p udp -m udp --dport 4500 -m state --state NEW -j ACCEPT
# Allow IPsec ESP payload traffic for client connects
$IPTABLES -A FORWARD --match policy --pol ipsec --dir in --proto esp -s 10.0.0.0/24 -j ACCEPT
$IPTABLES -A FORWARD --match policy --pol ipsec --dir out --proto esp -d 10.0.0.0/24 -j ACCEPT
# MSS fix for packets fragmentation
$IPTABLES -t mangle -A FORWARD --match policy --pol ipsec --dir in -s 10.0.0.0/24 -o $eth0 -p tcp -m tcp --tcp-flags SYN,RST SYN -m tcpmss --mss 1361:1536 -j TCPMSS --set-mss 1360
# Allow access 192.168.3.0/26 to 10.0.0.0/24 network
$IPTABLES -A OUTPUT -s 192.168.3.0/26 -d 10.0.0.0/24 -m state --state NEW -j ACCEPT
$IPTABLES -A FORWARD -s 192.168.3.0/26 -d 10.0.0.0/24 -m state --state NEW -j ACCEPT
# Allow internet connection
$IPTABLES -A INPUT -s 192.168.3.4 -m state --state NEW -j ACCEPT
$IPTABLES -A INPUT -s 10.0.0.0/24 -m state --state NEW -j ACCEPT
$IPTABLES -A INPUT -s 192.168.3.0/26 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -s 10.0.0.0/24 -m state --state NEW -j ACCEPT
$IPTABLES -A OUTPUT -s 192.168.3.0/26 -m state --state NEW -j ACCEPT
$IPTABLES -A FORWARD -s 10.0.0.0/24 -m state --state NEW -j ACCEPT
$IPTABLES -A FORWARD -s 192.168.3.0/26 -m state --state NEW -j ACCEPT
# Block all other traffic
$IPTABLES -A OUTPUT -m state --state NEW -j DROP
$IPTABLES -A INPUT -m state --state NEW -j DROP
$IPTABLES -A FORWARD -m state --state NEW -j DROP
# Add route for IPsec
$IP route add 10.0.0.0/24 via 192.168.3.4 dev $eth0