Set UFW firewall in Ubuntu

Source: Internet
Author: User

1: Installation

Sudo apt-Get install UFW

2: Enabled

Sudo UFW enable

Sudo UFW default deny

After running the preceding two commands, the firewall is enabled and automatically enabled when the system starts. Disable all external access to the local machine, but the local access to the external is normal.

3: enable/disable

Sudo UFW allow | deny [Service]

Open or close a port, for example:

Sudo UFW allow SMTP allows all external IP addresses to access the local port 25/tcp (SMTP ).

Sudo UFW allow 22/tcp allows all external IP addresses to access the 22/tcp (SSH) Port of the local machine.

Sudo UFW allow 53 allows external access to port 53 (TCP/UDP)

Sudo UFW allow from 192.168.1.100 allows this IP address to access all local ports

Sudo UFW allow proto UDP 192.168.0.1 port 53 to 192.168.0.2 port 53

Sudo UFW deny SMTP prohibit external access to the SMTP service

Sudo UFW Delete allow SMTP delete a rule created above

4: view the Firewall Status

Sudo UFW status

For general users, only the following settings are required:

Sudo apt-Get install UFW

Sudo UFW enable

Sudo UFW default deny

The preceding three commands are safe enough. If you need to open some services, use sudo UFW allow.

Enable/disable firewall ('disable' is set by default ')

Sudo UFW enable | disable

Change log status

Sudo UFW logging on | off

Set the Default policy (for example, "mostly open" vs "mostly closed ")

Sudo UFW default allow | deny

Permit or shield the port (you can view the service list in "status ). You can use "Protocol: Port" to specify a service name that exists in/etc/services, or use the meta-data package. The 'allow' parameter adds the entries to/etc/UFW/maps, while the 'deny' parameter is the opposite. The basic syntax is as follows:

Sudo UFW allow | deny [Service]

Display the listening status of the firewall and port. For more information, see/var/lib/UFW/maps. The numbers in the brackets are not displayed.

Sudo UFW status

UFW usage example:

Allow port 53

$ Sudo UFW allow 53

Disable port 53

$ Sudo UFW Delete allow 53

Allow port 80

$ Sudo UFW allow 80/tcp

Disable port 80

$ Sudo UFW Delete allow 80/tcp

Allow SMTP Port

$ Sudo UFW allow SMTP

Delete the SMTP port license

$ Sudo UFW Delete allow SMTP

Allow a specific IP Address

$ Sudo UFW allow from 192.168.254.254

Delete the preceding rule

$ Sudo UFW Delete allow from 192.168.254.254

Set UFW firewall in Ubuntu

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.