In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you the "Linux forced release occupied port and Linux firewall port open example analysis", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "Linux forced release occupied port and Linux firewall port open example analysis" this article.
When installing services such as nginx,mysql,tomcat, we will encounter that the ports we need to use are inexplicably occupied. Here's how to solve this problem.
When it comes to ports, firewalls have to be mentioned, and this article will briefly describe how to configure firewall development ports.
Various ways for Linux to check the situation of ports
The mapping of all ports is found in the / etc/services file
The Linux port is briefly introduced. The port number ranges from 0 to 65536. The purpose of each numbered end is as follows:
0-1023: well-known port, binding to common services (FTP,SSH)
1024-49151: register port for binding to some services
49152-65535: dynamic or private ports that can be used for any network connection
Ports are divided into TCP and UDP transport protocols.
Linux View Port status command
You can check the port situation with the following command. Click the command to adjust the usage details of each command:
Nmap command, port scan using
Netstat inspection development port
Lsof checks the port descriptor
# check the port nmap 127.0.0.00 bound to this machine. Check port 3306 netstat-anlp | grep 330 checks the 3306 interface lsof-iRanger 3306.
Linux release Occupy Port solution
The resolution steps are as follows:
Find the processes that occupy the port
Kill the process.
Use the following command:
# can be written as a command
Netstat-anp | grep 8080 | awk'{print $7}'| awk-F'/'{print $1}'| xargs kill-s 9
Each command has the following meanings:
Netstat-anp shows all network usage and shows the usage program
Grep 8080 matches the record of port 8080 (may contain 18080)
Awk'{print $7} 'outputs the seventh column of processes in the following form: 18989/nginx
Awk-F'/'{print $1} 'intercepts process PID:18989
Xargs kill-s 9 kills the process using the output of the previous command as an argument
Step-by-step solution to release occupied ports
Query whether the port is occupied
For example, if you need to query whether port 8080 is occupied, you can use the following command
Netstat-an | grep 8080
Query the processes that occupy the port
You can use the lsof command to view
Lsof-iPUR 8080
You can also use netstat and grep to view
Netstat-anp | grep 8080
The last line of the command is the PID and name of the process that occupies port 8080.
Kill the process that occupies the port
You can use the kill command to directly kill the process found in the previous step.
Kill-9 19664
Linux Firewall release Port
Linux Firewall on and off
The firewall described below is iptable and does not apply to firewalld.
Turn on the firewall (permanently effective after reboot): chkconfig iptables on
Turn off the firewall (permanently effective after reboot): chkconfig iptables off
Enable the firewall (effective immediately, invalidate after restart): service iptables start
Turn off the firewall (effective immediately, invalid after restart): service iptables stop
Restart the firewall: service iptables restart
Linux View Firewall status
You can view it using the following command:
/ etc/init.d/iptables status# or iptables statusiptables-L # can also be viewed directly in the configuration file vim / etc/sysconfig/iptables
Linux opens a port in the firewall
For example, to open port 8080, you can use the following command:
Iptables-An INPUT-p tcp-- dport 8080-j ACCEPT# also needs to restart the service service iptables restart#. You can also edit the configuration file vim / etc/sysconfig/iptables# directly and add a line at the end of the file. Develop all ports between 8080 and 8181: iptables-An INPUT-p tcp-- dport 8080 dport 8181-j ACCEPT.
Among them
The-A parameter is treated as adding a rule
-p specifies what the protocol is, our commonly used tcp protocol, of course, there is also udp
-dport is the target port. When data enters the server from the outside, it is the target port.
-if sport data is sent out of the server, it will be used for the data source port
-j specifies ACCEPT-receive or DROP does not receive
The above is all the contents of the article "Linux forced release of occupied ports and Linux firewall port opening example". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.