TransWikia.com

what are the options to close manual the port correctly or release the port on rhel machines?

Server Fault Asked on November 20, 2021

we have redhat 7.5 server

we are suspect that port 50070 not closed correctly by the service , ( we check by netstat and PID not found ) but from the log we can see that port is in use

so we try to do the following for example ,

ss --kill state listening src :50070
ss: unrecognized option '--kill'
Usage: ss [ OPTIONS ]
       ss [ OPTIONS ] [ FILTER ]
   -h, --help          this message
   -V, --version       output version information
   -n, --numeric       don't resolve service names
   -r, --resolve       resolve host names
   -a, --all           display all sockets
   -l, --listening     display listening sockets
   -o, --options       show timer information
   -e, --extended      show detailed socket information
   -m, --memory        show socket memory usage
   -p, --processes     show process using socket
   -i, --info          show internal TCP information
   -s, --summary       show socket usage summary
   -b, --bpf           show bpf filter socket information
   -Z, --context       display process SELinux security contexts
   -z, --contexts      display process and socket SELinux security contexts
   -N, --net           switch to the specified network namespace name

   -4, --ipv4          display only IP version 4 sockets
   -6, --ipv6          display only IP version 6 sockets
   -0, --packet        display PACKET sockets
   -t, --tcp           display only TCP sockets
   -u, --udp           display only UDP sockets
   -d, --dccp          display only DCCP sockets
   -w, --raw           display only RAW sockets
   -x, --unix          display only Unix domain sockets
   -f, --family=FAMILY display sockets of type FAMILY

   -A, --query=QUERY, --socket=QUERY
       QUERY := {all|inet|tcp|udp|raw|unix|unix_dgram|unix_stream|unix_seqpacket|packet|netlink}[,QUERY]

but ss not include the kill flag

what are the option to close the port correctly or release the port on rhel machines ?

the log is:

2020-07-18 21:26:22,753 INFO  impl.MetricsSystemImpl (MetricsSystemImpl.java:shutdown(606)) - NameNode metrics system shutdown complete.
2020-07-18 21:26:22,753 ERROR namenode.NameNode (NameNode.java:main(1783)) - Failed to start namenode.
java.net.BindException: Port in use: linux.gg.com:50070
        at org.apache.hadoop.http.HttpServer2.constructBindException(HttpServer2.java:1001)
        at org.apache.hadoop.http.HttpServer2.bindForSinglePort(HttpServer2.java:1023)
        at org.apache.hadoop.http.HttpServer2.openListeners(HttpServer2.java:1080)
        at org.apache.hadoop.http.HttpServer2.start(HttpServer2.java:937)
        at org.apache.hadoop.hdfs.server.namenode.NameNodeHttpServer.start(NameNodeHttpServer.java:170)
        at org.apache.hadoop.hdfs.server.namenode.NameNode.startHttpServer(NameNode.java:942)
        at org.apache.hadoop.hdfs.server.namenode.NameNode.initialize(NameNode.java:755)
        at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:1001)
        at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:985)
        at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1710)
        at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1778)
Caused by: java.net.BindException: Address already in use
        at sun.nio.ch.Net.bind0(Native Method)
        at sun.nio.ch.Net.bind(Net.java:433)
        at sun.nio.ch.Net.bind(Net.java:425)
        at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223)
        at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
        at org.mortbay.jetty.nio.SelectChannelConnector.open(SelectChannelConnector.java:216)
        at org.apache.hadoop.http.HttpServer2.bindListener(HttpServer2.java:988)
        at org.apache.hadoop.http.HttpServer2.bindForSinglePort(HttpServer2.java:1019)
        ... 9 more
2020-07-18 21:26:22,755 INFO  util.ExitUtil (ExitUtil.java:terminate(124)) - Exiting with status 1
2020-07-18 21:26:22,757 INFO  namenode.NameNode (LogAdapter.java:info(47)) - SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at 
************************************************************/
[root@linux hdfs]#
[root@linux hdfs]#
[root@linux hdfs]# netstat -tulpn | grep 50070 ( no PID number is returned ) 

One Answer

An open network socket is like a filehandle: once the program that holds the handle exits, the socket is definately closed. So I sugest the following (execute as root):

ss -tulpn | grep ":50070"

review the result, if any, that looks similar to this:

Netid  State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
udp    UNCONN     0      0      0.0.0.0:68                 0.0.0.0:*                   users:(("dhclient",pid=1670,fd=6))
udp    UNCONN     0      0      127.0.0.1:323                0.0.0.0:*                   users:(("chronyd",pid=1540,fd=1))
udp    UNCONN     0      0         [::1]:323                [::]:*                   users:(("chronyd",pid=1540,fd=2))
tcp    LISTEN     0      128    0.0.0.0:22                 0.0.0.0:*                   users:(("sshd",pid=1583,fd=3))

and if you find a program holding the port open, kill it with the kill command:

kill <pid>

But since the program that holds the open port is a service, I really suggest you consider other ways of closing the port:

  • systemctl stop <service> - that stops the service, and once it exits, the open port is gone as well...
  • modifying the config of the service not to open the port in question
  • use a firewall to deny access to this port

Answered by Martin on November 20, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP