Some Linux commands

Posted Jun 4, 20201 min read

See which ports are open

netstat -tlpn

Ubuntu open designated port
Under normal circumstances, when ubuntu is installed, iptables will be installed.

  1. Installation
    Type in the terminal

    sudo apt-get install iptables

  2. Add rules
    Type in the terminal

    iptables -I INPUT -p tcp --dport 80 -j ACCEPT

The middle 80 is the required open port

  1. Save the rules
    Type in the terminal

    iptables-save

After completing the above command, we have completed opening the designated port, but if the server is restarted at this time, the above rules will be gone, so we need to continue the rules

Persistence rules

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

  1. Install iptables-persistent

    sudo apt-get install iptables-persistent

  2. Persistence rules

    sudo netfilter-persistent save
    sudo netfilter-persistent reload

After completing the above operations, we can permanently open the ports we need
Modify the hosts file
vi /etc/hosts

At the end of the file, insert a structure similar to that under windows

127.0.0.1 www.9aw.cn

After the modification is completed, restart the network to take effect

/etc/init.d/network restart