Use ufw or iptables to configure the firewall in Ubuntu Linux

Source: Internet
Author: User

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:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.