Skip to main content
Share Your Experience: Take the 2024 Developer Survey
87 votes

How to terminate dead connections from the command line without restarting server

On linux kernel >= 4.9 you can use the ss command from iproute2 with key -K ss -K dst 192.168.1.214 dport = 49029 the kernel have to be compiled with CONFIG_INET_DIAG_DESTROY option enabled.
Pavel's user avatar
  • 871
86 votes
Accepted

Connecting to IP 0.0.0.0 succeeds. How? Why?

0.0.0.0 as a target address refers variously to a non-routable host or to “this host” (RFC 5735 section 3). In practice connecting to 0.0.0.0 is, in most scenarios, equivalent to connecting to ...
Stephen Kitt's user avatar
34 votes
Accepted

Are /dev/{udp,tcp} standardized or available everywhere?

This is a feature of the shell and not the operating system. So, for example,on Solaris 10 with ksh88 as the shell: % cat < /dev/tcp/localhost/22 ksh: /dev/tcp/localhost/22: cannot open However ...
Stephen Harris's user avatar
27 votes
Accepted

Linux 64-bit SSH port numbers?

Is it possible to configure Linux to use 64 bit ports? You cannot change a parameter to use 64bit ports in TCP/UDP. You could create similar protocols, but you would only be able to communicate with ...
Eduardo Trápani's user avatar
23 votes
Accepted

Where has /dev/tcp gone?

/dev/{tcp,udp} are only bash internals. The tcp and udp sockets stored in /proc/net/{tcp,udp} by kernel
Ipor Sircer's user avatar
  • 14.6k
22 votes

How to call lsof properly to retrieve all TCP connections?

The correct syntax is: lsof -a -i4 -i6 -itcp This selects TCP sockets that are IPv4 or IPv6.
CodeWriter23's user avatar
22 votes
Accepted

How to terminate a TCP connection established by bash itself?

That command opened the connection on file descriptor 3. So to close the connection, you need to close file descriptor 3. To do so: exec 3<&-
phemmer's user avatar
  • 72k
19 votes

How to tell how much memory TCP buffers are actually using?

/proc/net/sockstat, specifically the mem field, is where to look. This value is is reported in kernel pages and corresponds directly to /proc/sys/net/ipv4/tcp_mem. At the individual socket level, ...
Mike Fischer's user avatar
17 votes
Accepted

Is accepting RELATED,ESTABLISHED for all sources in iptables considered "too open"?

I would not consider ESTABLISHED and RELATED traffic too open. You may be able to omit RELATED, but should definitely allow ESTABLISHED. Both of these traffic categories use conntrack states. ...
BillThor's user avatar
  • 8,975
17 votes
Accepted

TCP *:hbci (LISTEN) - What does hbci mean?

Does anyone know what hbci means or refers to? HBCI stands for "Home Banking Computer Interface", see http://openhbci.sourceforge.net/. The same port number is also used by the "RemoteWare Client", ...
DepressedDaniel's user avatar
17 votes
Accepted

Why telnet is considered to be a protocol? Isn't it just a simple TCP send/echo program?

Telnet is defined in RFC 854. What makes it (and anything else) a protocol is a set of rules/constraints. One such rule is that Telnet is done over TCP, and assigned port 23 - this stuff might seem ...
Michael Stum's user avatar
17 votes

Can I have a single server listen on more than 65535 ports by attaching an IPv4 address

The limit on listening ports is per address regardless of IPv4 or IPv6. The limitation comes from TCP and UDP packet headers which are two bytes and so port numbers for TCP and UDP can only be in the ...
Philip Couling's user avatar
16 votes

Linux 64-bit SSH port numbers?

Having a 64b port makes it almost impossible to randomly attack a service, targeting either DoS or a login. Like ssh -p 141592653589793238 my.site.com And how would the client know about ...
Gilles 'SO- stop being evil''s user avatar
13 votes

Kill any service running at a specific port

If you want to kill any service or process running on port number 8080 then first you need to find the 8080 port process identification number(PID) and then kill it. Run the following command to find ...
Mahfuz's user avatar
  • 231
13 votes

Read "/proc" to know if a process has opened a port

Please cat /proc/$PID/net/tcp and you will get output like this sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode 0: 00000000:01BB 00000000:0000 0A ...
PHZ.fi-Pharazon's user avatar
13 votes
Accepted

In linux does "/proc/sys/net/ipv4/tcp_keepalive_time" has impact on both client & server?

Linux kernel's built-in support for TCP keepalive affects all keepalive-enabled TCP sockets. TCP keepalive is not enabled by default, though: the applications must explicitly request keepalive ...
MariusPontmercy's user avatar
12 votes

How does tcp-keepalive work in ssh?

The TCPKeepAlive option is actually a very different method of keeping connections alive from ClientAlive-like or ServerAlive-like options. Are per BSD SSH manual page, we can read that: The ...
kenorb's user avatar
  • 21.1k
12 votes
Accepted

Debian Stretch source tcp port is *always* even

It's to reduce contention between connect() and bind() (appeared in Linux 4.2; Jessie has 3.16 and Stretch has 4.9): commit 07f4c90062f8fc7c8c26f8f95324cbe8fa3145a5 Author: Eric Dumazet Date: Sun ...
Ferenc Wágner's user avatar
12 votes
Accepted

Detailed output of ss command

Meaning of some of these fields can be deduced from source code of ss and Linux kernel. Information you see is printed by tcp_show_info() function in iproute2/misc/ss.c. advmss: In ss.c: s.advmss ...
Arkadiusz Drabczyk's user avatar
11 votes

Is accepting RELATED,ESTABLISHED for all sources in iptables considered "too open"?

ESTABLISHED and RELATED are features of "stateful" packet filtering, where filtering does not just depend on a static rule set but also on the context, within which packets are considered. You need ...
countermode's user avatar
  • 7,583
11 votes
Accepted

When/how does Linux decides to close a socket on application kill?

A broad question. Perhaps someone can weigh in on your question about the kernel TCP stack between specific kernel versions. A couple of general answers: From the client side In the event of a ...
111---'s user avatar
  • 4,546
9 votes

Allowing a regular user to listen to a port below 1024

If the service is run by systemd, set the desired port in the service configuration open the unit file (usually /etc/systemd/system/something.service), go to the [Service] section, add a new line ...
Martin's user avatar
  • 203
9 votes
Accepted

"netstat -p"/"ss -p" not showing the process of a listening port

The point on netstat not showing the process information on some situations, for instance NFS, is that NFS is a kernel module, and as such, it does not run as a normal process, and does not have a PID....
Rui F Ribeiro's user avatar
9 votes
Accepted

netstat show port number instead of process name

netstat is translating the (default) port to the service name, it gets this mapping from /etc/services file. So, you can get the port from /etc/services: grep '^postgresql' /etc/services Or better ...
heemayl's user avatar
  • 56.5k
9 votes

How to properly configure a tun/tap Interface in linux?

I would just bridge the two, in which case there will be no need for an IP address on tap0, i.e.; brctl addif br0 tap0 ip link set tap0 master br0 or if you don't already have bridge-utils installed,...
Shōgun8's user avatar
  • 711
9 votes

What exactly happens when I enable net.ipv4.ip_forward=1?

M's kernel receives a packet whose destination IP address indicates it's not meant for M. What will it do? When ip_forward=0, it thinks: "I don't know why this got sent to me and I don't really ...
telcoM's user avatar
  • 98k
8 votes

How to tell how much memory TCP buffers are actually using?

This is a very complex question that may require delving into the kernel source to find an answer. It does not seem as though the buffer is included in the process's RES statistic. See this article (...
Tyler Chambers's user avatar
8 votes
Accepted

Which Unix-like system really provides the /dev/tcp special file?

I think the Bash documentation is somewhat misleading on this topic. Looking at the code, even going back to version 2.04 where network redirections were introduced, /dev/tcp and /dev/udp works as ...
Stephen Kitt's user avatar
8 votes
Accepted

How to use bash to create a socket server and allow multiple clients in the same port?

nc does not handle multiple connected clients in parallel and is the wrong tool for this job. There are quite a few right tools for this job, including: Bernstein tcpserver (original or djbwares) or ...
JdeBP's user avatar
  • 69.1k
7 votes

How to connect ssh from a specified port?

The command syntax you're looking for perhaps is this. ssh -p XXX user@remotehostip You have to change option's order. Try it now, it works for me. Best regards.
Rafael Garcia's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible