some of this rules broke my Qemu DHCP and NAT routing : IPTABLES="/sbin/iptables"
IP6TABLES="/sbin/ip6tables"
MODPROBE="/sbin/modprobe"
RMMOD="/sbin/rmmod"
ARP="/usr/sbin/arp"
IPTABLES−AINPUT−picmp−jDROPLOGIPTABLES -A OUTPUT -p icmp -j DROPLOG
$IPTABLES -A FORWARD -p icmp -j DROPLOG
IPTABLES−AINPUT−ilo−jACCEPTIPTABLES -A OUTPUT -o lo -j ACCEPT
$IPTABLES -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
$IPTABLES -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
IPTABLES−AINPUT−ptcp−mmultiport−−dports135,137,138,139,445,1433,1434−jDROPIPTABLES -A INPUT -p udp -m multiport
--dports 135,137,138,139,445,1433,1434 -j DROP
$IPTABLES -A INPUT -m state --state INVALID -j DROP
$IPTABLES -A OUTPUT -m state --state INVALID -j DROP
$IPTABLES -A FORWARD -m state --state INVALID -j DROP
IPTABLES−AINPUT−mstate−−stateNEW−ptcp−−tcp−flagsALLALL−jDROPIPTABLES -A INPUT -m state --state NEW -p tcp --tcp-flags ALL NONE -j DROP
IPTABLES−AINPUT−s0.0.0.0/7−jDROPIPTABLES -A INPUT -s 2.0.0.0/8 -j DROP
IPTABLES−AINPUT−s5.0.0.0/8−jDROPIPTABLES -A INPUT -s 7.0.0.0/8 -j DROP
IPTABLES−AINPUT−s10.0.0.0/8−jDROPIPTABLES -A INPUT -s 23.0.0.0/8 -j DROP
IPTABLES−AINPUT−s27.0.0.0/8−jDROPIPTABLES -A INPUT -s 31.0.0.0/8 -j DROP
IPTABLES−AINPUT−s36.0.0.0/7−jDROPIPTABLES -A INPUT -s 39.0.0.0/8 -j DROP
IPTABLES−AINPUT−s42.0.0.0/8−jDROPIPTABLES -A INPUT -s 49.0.0.0/8 -j DROP
IPTABLES−AINPUT−s50.0.0.0/8−jDROPIPTABLES -A INPUT -s 77.0.0.0/8 -j DROP
IPTABLES−AINPUT−s78.0.0.0/7−jDROPIPTABLES -A INPUT -s 92.0.0.0/6 -j DROP
IPTABLES−AINPUT−s96.0.0.0/4−jDROPIPTABLES -A INPUT -s 112.0.0.0/5 -j DROP
IPTABLES−AINPUT−s120.0.0.0/8−jDROPIPTABLES -A INPUT -s 169.254.0.0/16 -j DROP
IPTABLES−AINPUT−s172.16.0.0/12−jDROPIPTABLES -A INPUT -s 173.0.0.0/8 -j DROP
IPTABLES−AINPUT−s174.0.0.0/7−jDROPIPTABLES -A INPUT -s 176.0.0.0/5 -j DROP
IPTABLES−AINPUT−s184.0.0.0/6−jDROPIPTABLES -A INPUT -s 192.0.2.0/24 -j DROP
IPTABLES−AINPUT−s197.0.0.0/8−jDROPIPTABLES -A INPUT -s 198.18.0.0/15 -j DROP
IPTABLES−AINPUT−s223.0.0.0/8−jDROPIPTABLES -A INPUT -s 224.0.0.0/3 -j DROP
IPTABLES−AINPUT−jREJECTLOGIPTABLES -A OUTPUT -j REJECTLOG
$IPTABLES -A FORWARD -j REJECTLOG
exit 0
The script you've posted is quite comprehensive and implements a variety of iptables rules for hardening your system's network security. However, configuring such iptables rules can indeed interfere with services that rely on specific networking functionalities, such as DHCP and NAT used by QEMU for providing internet access to virtual machines.
To troubleshoot and potentially fix DHCP and NAT issues that arose after applying these iptables rules, consider the following steps and checks:
IP Forwarding: The script seems to enable IP forwarding (echo 1 > /proc/sys/net/ipv4/ip_forward) but immediately disables it (echo 0 > /proc/sys/net/ipv4/ip_forward). For NAT to work, IP forwarding must be enabled. Ensure that it is enabled by setting echo 1 into /proc/sys/net/ipv4/ip_forward.
ACCEPT Rules for DHCP: Your iptables configuration does not explicitly allow for DHCP traffic. DHCP clients use UDP port 68 as the source port and UDP port 67 as the destination port when communicating with DHCP servers. To allow DHCP traffic, you may need to add rules to accept this traffic. For example:
NAT Configuration: For NAT to work correctly, you need to ensure that you have masquerade (or SNAT) rule(s) in place for the outbound traffic. If your internal network is, for example, 192.168.122.0/24 and your outgoing network interface is eth0, you need a rule like:
$IPTABLES -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Default Policy to DROP: Your script sets the default policies for INPUT, FORWARD, and OUTPUT chains to DROP. While this is good for security, it will block all traffic that doesn't explicitly match an ACCEPT rule. Ensure that after enabling IP forwarding, allowing DHCP, and configuring NAT as mentioned above, you also review and add any necessary rules to permit specific traffic needed by your services.
Logging and Debugging: You have extensive logging in place. Reviewing the logs (/var/log/kern.log, /var/log/messages, or via dmesg) for dropped packets or rejected connections can give insights into what might be getting blocked unexpectedly.
Connection Tracking Modules: Loading connection tracking modules for FTP and IRC can be beneficial for those specific services but shouldn't directly affect DHCP/NAT. Ensure any other required modules for your use case are loaded.
IP6Tables: If your setup uses IPv6, don't forget that you've set the default policies for all chains in ip6tables to DROP as well. Make sure to adjust ip6tables rules analogous to iptables for IPv6 traffic.
Final Advice: Be mindful that security rules and configurations should be tailored to your specific use case and environment. It might be necessary to adjust or add rules based on your actual network layout, services running, and their requirements.
Adjusting iptables rules requires careful planning and testing to avoid locking yourself out or disrupting services. Always back up your current iptables rules (iptables-save > iptables.bak) before making changes.