161
votes
Simple way to create a tunnel from one local port to another?
With socat on the server:
socat tcp-listen:8001,reuseaddr,fork tcp:localhost:8000
By default, socat will listen on TCP port 8001 on any IPv4 or IPv6 address (if supported) on the machine. You can ...
91
votes
Accepted
Can TCP provide more than 65535 ports?
Looking at the RFC for TCP: RFC 793 - Transmission Control Protocol, the answer would seem to be no because of the fact that a TCP header is limited to 16-bits for the source/destination port field.
...

slm♦
- 346k
80
votes
Killing tcp connection in linux
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.
77
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”. In practice connecting to 0.0.0.0 is equivalent to connecting to localhost. (Strictly speaking it isn’t valid as ...
68
votes
How to create a TCP listener?
you can create a port listener using Netcat .
root@ubuntu:~# nc -l 5000
you can also check if port is open or not using netstat command .
root@vm-ubuntu:~# netstat -tulpen | grep nc
tcp 0 ...
66
votes
Accepted
Is it possible to connect to TCP port 0?
Just to make sure we're on the same page (your question is ambiguous this way), asking to bind TCP on port 0 indicates a request to dynamically generate an unused port number. In other words, the ...
66
votes
Accepted
How to create a TCP listener?
You could use nc -l as a method to do what you are looking for. Some implementations of nc have a -L option which allows the connections to persist.
If you only need them for a little while you ...
56
votes
Kill any service running at a specific port
You can try fuser:
fuser -k 4990/tcp
Or using lsof to get the process id, then feed to kill:
kill $(sudo lsof -t -i:4990)
50
votes
Accepted
How to close ports in Linux?
Nmap is a great port scanner, but sometimes you want something more authoritative. You can ask the kernel what processes have which ports open by using the netstat utility:
me@myhost:~$ sudo netstat -...
48
votes
Accepted
Why are IPv4 TCP connections showing as tcp6?
This is happening because by default, AF_INET6 sockets will actually work for both IPv4 and IPv6. See section 3.7 - Compatibility with IPv4 Nodes of RFC 3493 - Basic Socket Interface Extensions for ...
45
votes
Accepted
/dev/tcp not found
You have to use it in redirections:
Bash handles several filenames specially when they are used in
redirections, as described in the following table:
...
/dev/tcp/host/port
If host ...
37
votes
Killing tcp connection in linux
Originally from: http://rtomaszewski.blogspot.sk/2012/11/how-to-forcibly-kill-established-tcp.html
To "kill" a socket, you must send a TCP reset packet. To send it (and be accepted by the other side),...
33
votes
How do I work out which port to log in on with SSH?
First check on the config file which port is configured:
$ sudo grep Port /etc/ssh/sshd_config
Port 22
Then either restart ssh to make sure it loads the config you just saw or find out on which port ...
33
votes
Accepted
Changing the TCP RTO value in Linux
The reason you can't alter the RTO specifically is because it is not a static value. Instead (except for the initial SYN, naturally) it is based on the RTT (Round Trip Time) for each connection. ...
33
votes
Accepted
Read "/proc" to know if a process has opened a port
I can read the /proc/$PID/net/tcp file for example and get information about TCP ports opened by the process.
That file is not a list of tcp ports opened by the process. It is a list of all open tcp ...
30
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 ...
26
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 ...
20
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.
20
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
19
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<&-
17
votes
Accepted
WITHOUT using network command lines in linux, how to know list of open ports and the process that owns them?
You should be able to find all open ports in /proc/net/tcp and /proc/net/udp. Each of those files have an inode column, which can be used to find the process owning that socket.
Once you have an ...
17
votes
Accepted
How to connect ssh from a specified port?
That is not easily possible. How that can be done depends on where the source port shall be seen: Locally, too, or is it enough if it's the right port from the perspective of the external network?
...
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", ...
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 ...
16
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.
...
16
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, ...
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 ...
15
votes
How to close ports in Linux?
To "close" the port you can use iptables
sudo iptables -A INPUT -p tcp --dport 23 -m state --state NEW,ESTABLISHED -j DROP
14
votes
How to close ports in Linux?
A Linux system has a so called loopback interface, which is for internal communication. Its hostname is localhost and its IP address is 127.0.0.1.
When you run nmap on localhost, you actually run the ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
tcp × 576networking × 179
linux × 157
socket × 51
iptables × 48
udp × 40
ssh × 35
ip × 32
kernel × 26
linux-kernel × 25
netstat × 24
centos × 23
netcat × 22
ubuntu × 20
bash × 19
firewall × 19
tcpdump × 19
proxy × 15
port-forwarding × 15
socat × 15
debian × 14
security × 14
tcp-ip × 14
http × 13
port × 12