Iptables
(Redirected from Iptables -t)
Jump to navigation
Jump to search
iptables
(1998) command line utility allows to modify Linux kernel firewall rules.
Basic commands[edit]
apt-get install iptables-persistent
iptables-save
andiptables-restore
Options[edit]
- Add:
iptables -A
- Delete:
iptables -D
- Insert:
iptables -I
Examples[edit]
KVM VNC remote viewer iptables -t nat -A PREROUTING -i eno1 -p tcp --dport 5900 -j DNAT --to 127.0.0.1:5900 sysctl -w net.ipv4.ip_forward=1 sysctl -p /etc/sysctl.conf
Port forwarding[edit]
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to-destination IP_DESTINATION
iptables -t nat -A POSTROUTING -p tcp -d IP_DESTINATION --dport 2222 -j MASQUERADE
echo 1 > /proc/sys/net/ipv4/ip_forward
- Block all output traffic:
iptables -A OUTPUT -o ethXXX -j DROP
- Open a port:
iptables -I INPUT -p tcp --dport XXX -j ACCEPT
Block all but a range[edit]
iptables -I OUTPUT -m iprange --dst-range <remote_ip> -j ACCEPT
iptables -I INPUT -m iprange --src-range <remote_ip> -j ACCEPT
iptables -P INPUT DROP
iptables -P OUTPUT DROP
netfilter-persistent save
Block all but one IP[edit]
iptables -I OUTPUT -d <remote_ip> -j ACCEPT
iptables -I INPUT -s <remote_ip> -j ACCEPT
iptables -I OUTPUT -d <remote_ip> -j ACCEPT
iptables -I INPUT -s <remote_ip> -j ACCEPT
iptables -P INPUT DROP
iptables -P OUTPUT DROP
Allow ssh connections only from specific IPs[edit]
iptables -A INPUT -p tcp --dport 22 -s YourIP -j ACCEPT
iptables -A INPUT -p tcp --dport 22 -j DROP
netfilter-persistent save
Clear iptables rules[edit]
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -F
iptables -t mangle -F
iptables -F
iptables -X
Flush[edit]
iptables -F
- (no output)
iptables -t nat -F
iptables -t YOUR_TABLE_NAME -F
Activities[edit]
- Read
iptables
Ubuntu howto: https://help.ubuntu.com/community/IptablesHowTo - Read archlinux documentation: https://wiki.archlinux.org/index.php/iptables
- Read Stackoverflow iptables questions: https://stackoverflow.com/questions/tagged/iptables?tab=Votes
- Review your current iptables configuration
iptables-save
,iptables-restore
Related terms[edit]
See also[edit]
iptables
,ufw
, firewalld, nftables firewall-cmd,netfilter-persistent, iptables -L
,iptables-save
,iptables-restore
, Netfilteriptables
ufw
firewalld
nftables
firewall-cmd
ipfw (FreeBSD)
PF (OpenBSD)
, netsh advfirewallnftables
- Palo Alto firewalls: PAN-OS
- Port knocking,
fail2ban
[3]fwknop
, DenyHosts
Advertising: