UFW firewall prohibits IP address access to Ubuntu Server

Source: Internet
Author: User
Some Ubuntu servers need to prohibit access from some IP addresses. I wanted to use/etc/hosts. allow and/etc/hosts. deny to limit the access. Later I used the utw firewall. Vi/etc/hosts. allowALL: 10.0.0.163, 10.0.0.162, 10.0.0.161vi/etc/hosts. denyALL: after ALL is set,/etc/init. d/netwo has an Ubuntu server that needs to disable some IP addresses for access. I wanted to use/etc/hosts. allow and/etc/hosts. deny was used as the limit, but utw firewall was used later.
 
Vi/etc/hosts. allow
ALL: 10.0.0.163, 10.0.0.162, 10.0.0.161
 
Vi/etc/hosts. deny
ALL: ALL
 
After setting
/Etc/init. d/networking restart
 
Use a 10.0.0.151 instance for testing. telnet Ubuntu 22 cannot be connected, and telnet Ubuntu 80 cannot be connected. You can use the Ubuntu server of the browser to access the instance. Check whether the problem is solved, there are other ways to solve this problem later. You can use utw to solve it.
 
Install ufw
Sudo apt-get install ufw
 
Enable ufw
Sudo ufw enable
 
Block all external access to the Local Machine
Sudo ufw default deny
 
Allow all external IP addresses to access port 22/tcp (ssh) of the Local Machine
Sudo ufw allow 22/tcp
 
Allow this IP address to access all local ports
Sudo ufw allow from 10.0.0.163
 
Sudo ufw allow from 10.0.0.162
 
Sudo ufw allow from 10.0.0.161
 
View Firewall Status
Sudo ufw status
 
Delete a rule created above
Sudo ufw delete allow smtp
 
Firewall rule file path
/Lib/ufw/user. rules
 
Disable Firewall
Sudo ufw disable
Related Article

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.