Firewall

From Ever changing code
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Disable firewall

Preview all iptables rules

sudo iptables -L -n

Example output

piotr@ubudesk64:~$ sudo iptables -L -n
[sudo] password for piotr: 
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:53
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:53
ACCEPT     udp  --  0.0.0.0/0            0.0.0.0/0            udp dpt:67
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:67 

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  0.0.0.0/0            192.168.122.0/24     state RELATED,ESTABLISHED
ACCEPT     all  --  192.168.122.0/24     0.0.0.0/0           
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           
REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-port-unreachable
REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-port-unreachable

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Save existing firewall rules

sudo iptables-save > firewall.rules

Issue the following commands to stop firewall:

sudo iptables -X
sudo iptables -t nat -F
sudo iptables -t nat -X
sudo iptables -t mangle -F
sudo iptables -t mangle -X
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
sudo iptables -P OUTPUT ACCEPT

Backup and restore rules

iptables-save > firewall.rules     #dumps rules to the file. This contains all rules just missing 'iptable' word
iptables-restore < firewall.rules  #flushes memory and loads all rules from a file

Permanent rules are in /etc/sysconfig/iptables file that is loaded each time system boots up.


ufw - the default firewall configuration tool in Ubuntu

It is developed to simplyfy iptables firewall configuration, ufw provides a user friendly way to create an IPv4 or IPv6 host-based firewall. To disable ufw, enter:

sudo ufw disable