Ubuntu Install UFW Firewall

Source: Internet
Author: User

sudo apt-get install ufw 

For general users, only the following settings are required:
sudo apt-get install UFW
sudo UFW enable
sudo ufw default deny

The above three commands are safe enough, if you need to open some services, then use sudo ufw allow to open.

Enable
default deny #运行以上两条命令后,开启了防火墙,并在系统启动时自动开启。 #关闭所有外部对本机的访问,但本机访问外部正常。 
Turn ON/off
sudo ufw allow|deny [service] 
Open or close a port, for example:
sudo UFW allow SMTP#允许所有的外部IP访问本机的25/tcp (SMTP) portsudo UFW allow 22/tcp # Allow all external IPs to access native 22/TCP (SSH) ports sudo UFW let 53  #允许外部访问53端口 (TCP/UDP) sudo UFW allow from  192.168.1.100  #允许此IP访问所有的本机端口  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  #删除上面建立的某条规则  span>                 
View firewall status
sudo ufw status 
Add:
#开启/关闭防火墙 (默认设置是’disable’)ufw enable|disable#转换日志状态ufw logging on|off#设置默认策略 (比如 “mostly open” vs “mostly closed”)ufw default allow|deny#许可或者屏蔽某些入埠的包 (可以在“status” 中查看到服务列表[见后文])#可以用“协议:端口”的方式指定一个存在于/etc/services中的服务名称,也可以通过包的meta-data。 ‘allow’ 参数将把条目加入 /etc/ufw/maps ,而 ‘deny’ 则相反。基本语法如下:ufw allow|deny [service]#显示防火墙和端口的侦听状态,参见 /var/lib/ufw/maps。括号中的数字将不会被显示出来。ufw status
UFW Use Example:
#允许 53 Port $sudo ufw allow53 #禁用 53 Port $ sudo UFW delete allow 53< Span class= "hljs-comment" > #允许 80 Port $ sudo UFW allow 80/tcp #禁用 80 Port $ sudo UFW delete allow 80/tcp< Span class= "Hljs-comment" > #允许 SMTP Port $ sudo UFW allow Smtp #删除 SMTP Port License $ sudo UFW delete Allow Smtp #允许某特定 ip$ sudo UFW allow from 192.168. 254.254 #删除上面的规则 $ sudo UFW delete allow from 192.168. 254.254             

Note
Why the LAN ping does not pass the MAC host:
1. Network connectivity or network instability
2. Mac computer lock screen or shutdown
3. Firewall settings
4. ICMP protocol settings

Ubuntu Install UFW Firewall

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.