Home >Operation and Maintenance >Linux Operation and Maintenance >How to view and operate ports in Widows and Linux
Open cmd
1.netstat -n
View all ports used by this machine
①.proto represents the protocol There are two types: tcp and udp
②.Local Address represents the IP of the local machine, followed by the port number we use
③.Foreign Address connects to the IP address of the external server, and the server port
④ .State: Indicates some specific states, such as: LAST_ACK waiting for the packet used to die
2. Confirm the port number to be queried
Command netstat -aon | findstr 1044 (specified port number)
The last number in the query result is the pid of the current program or service
3. Enter the command: tasklist|findstr 2612 (enter the pid queried above)
This way you can view the programs running on this port
and then query it from the task manager, you can see the program
4. If we use the two options of specifying the port number
①. End this in the task manager After the program running on the port is finished, you can use this port number
②. Continue to enter the command on the cmd interface: taskkill /f /pid 2612 (enter the queried pid), or you can kill the program
Linux
netstat -tln #Find all occupied ports
netstat -tln | grep 80 #Find the specified occupied port
Install lsof
yum install lsof
Through lsof we can know which program our port belongs to
lsof -i:80 #Query port
kill -9 #Kill the process id more Use spaces to separate process IDs
For more Linux articles, please visit the Linux Tutorial column to learn!
The above is the detailed content of How to view and operate ports in Widows and Linux. For more information, please follow other related articles on the PHP Chinese website!