Tuesday, August 12, 2008

Test firewall setting using netcat

1) Open a port on a system inside firewall (system 1)
#nc -l port_number
eg: nc -l 1234 

2) Echo command on box outside the firewall (system 2)
#echo foobar | nc ip_address port_number
eg: echo foobar | nc 192.168.1.100   1234

"foobar" should be echoed on terminal of system 1

Other examples

 Receving System
#nc -l 1234 > filename.out
#nc host.example.com 1234
#nc -l 1234 | dd of=/dev/sda 
#nc -l 1234 | dd of=1gfile


Sending System
#nc host.example.com 1234 < filename.in
#dd if=/dev/sda | nc host.example.com 124
#dd if=/dev/zero bs=1G count=1 | nc host.example.com 1234

Example 2
# nc -w 10 -vz 192.168.100.10 443
Connection to 192.168.100.10 443 port [tcp/https] succeeded!
# nc -w 10 -vz 192.168.100.10 444
nc: connect to 192.168.100.10 port 444 (tcp) timed out: Operation now in progress

No comments: