Ever hop onto a server where the network admin may have been a bit over-caffeinated when they were locking down the firewall? What if they also locked down egress along with ingress? They want you to prove you cannot connect outbound, but you cannot even install ‘telnet’ or ‘nc’ since yum/apt can’t get outbound. While that is proof in and of itself, what if you needed something more for some reason?
Assuming you have root access and ‘telnet’ or ‘nc’ is not installed, you can use the bash networking features (see REDIRECTION man page). The example below shows connections that succeed since they return instantly:
[[email protected] ~]# echo > /dev/tcp/184.108.40.206/80 [[email protected] ~]# echo > /dev/tcp/220.127.116.11/443 [[email protected] ~]# echo > /dev/tcp/google.com/443 [[email protected] ~]#
You can tell the connection failed as the command will hang or return an error about ‘connection refused’.
Another way around this is to use curl if it is available. Below is an example for checking if you can connect to port 25 on the remote server:
[[email protected] ~]# curl -v telnet://18.104.22.168:25 * About to connect() to 22.214.171.124 port 25 (#0) * Trying 126.96.36.199... * Connected to 188.8.131.52 (184.108.40.206) port 25 (#0)