Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to operate Network Port in Linux system

Shulou Source: shulou.com Published: 2022-06-01 17:01:35 09月28日 Update

Linux system how to operate the network port, in response to this problem, this article details the corresponding analysis and solutions, hoping to help more small partners who want to solve this problem to find a simpler and easier way.

close port

The code is as follows:

iptables -A INPUT -p tcp --dport 111 -j DROP

open ports

The code is as follows:

iptables -A INPUT -p tcp --dport 111 -j ACCEPT

Develop discrete ports (including single):

The code is as follows:

iptables -A INPUT -p tcp -m multiport --dport 21,20 -j ACCEPT

Everything else is closed:

The code is as follows:

iptables -A INPUT -p tcp -j REJECT --reject-with tcp-reset

Open Continuous Ports:

The code is as follows:

iptables -A RH-Firewall-1-INPUT -m state --state NEW -m udp -p udp --dport 8001:8140 -j ACCEPT

You can also modify/etc/sysconfig/iptables directly. How to write it, refer to the open port, or fill in the command above.

Restart iptables

The code is as follows:

service iptables restart

Linux port occupied solution

Sometimes after closing the software, the background process dies, causing the port to be occupied. Take JBoss port 8083 occupied as an example to list the detailed resolution process.

Solution:

1. Find occupied ports

The code is as follows:

netstat -tln

netstat -tln | grep 8083

netstat -tln View port usage, while netstat -tln| grep 8083 is only used to view port 8083

2. Which program does the port belong to? Which process is the port occupied by?

The code is as follows:

lsof -i :8083

3. Kill the process occupying the port

The code is as follows:

kill -9

process ID

About Linux system how to operate the network port problem answer to share here, hope the above content can have some help to everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.

Tags: Port code process problem system network situation method more help answer easy easy content single background command boy buddy sometimes Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information macOS Microsoft MySQL Linux