ubuntu open designated port

Today, I encountered some problems when opening the web service on the server for others to access. When others used ip and port access in the internal network, they could not access it. After a long time toss, I found that the port was not opened.
Understand that ports in general Linux are closed by default, and you need to open it yourself when you need to open it

Open port##

Since the os used by my server is Ubuntu, here is the method under Ubuntu. Other linux should be similar, and you need to try it yourself

Install iptables

Under normal circumstances, iptables will be installed when ubuntu is installed, if not, install it.

  1. installation
    Type in the terminal
    $ sudo apt-get install iptables
  2. Add rule
    Type in the terminal
    $ sudo iptables -I INPUT -p tcp --dport 80 -j ACCEPT

The 80 in the middle is the port that needs to be opened

  1. Save rules
    Enter $ sudo iptables-save in the terminal

After completing the above command, we have completed the opening of the specified port, but if the server restarts at this time, the above rules are gone, so we need to perform a continuous operation on the rules

Persistence rules###

Here we need to install some tools to help us achieve, here we use iptables-persistent

  1. Install iptables-persistent
    $ sudo apt-get install iptables-persistent
  2. Persistence rules 12 sudonetfilter−persistent save sudo netfilter-persistent reload

After completing the above operations, we can permanently open the ports we need

Note:

Recommended Posts

ubuntu open designated port
Open SSH service under Ubuntu
Open SSH service under Ubuntu
Tencent Cloud Ubuntu 18.04 open root login
Ubuntu19.10 open ssh service (detailed process)
Install Zimbra Open Source Edition on Ubuntu 14.04
How to open root account in Ubuntu20.04