Use ufw or iptables to configure the firewall in Ubuntu Linux
The firewall only supports ssh (port 22) and http (port 80 ).
In Ubuntu Linux, ufw can be used as follows:
Sudo ufw enable &&\
Sudo ufw default deny &&\
Sudo ufw allow 22/tcp &&\
Sudo ufw allow 80/tcp &&\
Sudo ufw status
You can delete it like this, for example, port 80:
Sudo ufw delete allow 80/tcp
For more information about the sequence of Ubuntu ufw firewall rules, see
Ubuntu uses iptables to do this:
Sudo ufw disable & sudo ufw default allow sets INPUT/FORWARD/OUTPUT to ACCEPT. If it is DENY, the next step will interrupt all network access to the system, including ssh.
Sudo iptables-F & sudo iptables-X & sudo iptables-Z & sudo iptables-L
Sudo iptables-a input-m state -- state ESTABLISHED, RELATED-j ACCEPT
Sudo iptables-a input-I lo-j ACCEPT
Sudo iptables-a input-p tcp-I eth0 -- dport 22-j ACCEPT
Sudo iptables-a input-p tcp-I eth0 -- dport 80-j ACCEPT
Sudo iptables-a input-j DROP
Iptables-save>/etc/iptables. up. rules switch to the root user for execution. sudo will prompt that you do not have the permission. RedHat's save operation is service iptables save.
Add a line to the end of sudo nano/etc/network/interfaces and apply the firewall rules when the network starts:
Pre-up iptables-restore </etc/iptables. up. rules
View the configured rules:
Sudo iptables-nvL -- line-numbers
Insert a rule to 6th of the INPUT chain:
Sudo iptables-I INPUT 6-j DROP
Modify the 6th rules of the INPUT chain:
Sudo iptables-r input 6-j ACCEPT
Delete 6th rules of the INPUT chain:
Sudo iptables-d input 6
For more iptables tutorials, see the following:
Disable the default firewall in CentOS 7.0 and enable the iptables firewall.
Iptables examples
Linux Firewall iptables
Basic use of iptables backup, recovery, and firewall scripts
Detailed description of firewall iptables usage rules in Linux
Iptables firewall settings in Linux
This article permanently updates the link address: