2. Networking
-
Basic tools:
ip addressip addrip aip addr show loip routeip rping -c 3 8.8.8.8dig linuxcommand.orgdig linuxcommand.org +shortping -c 3 linuxcommand.orgtraceroute linuxcommand.orgtracepath linuxcommand.org -
For downloading files we can use
wgetorcurl:wget http://linuxcommand.org/index.phpless index.phpwget -O index.html 'http://linuxcommand.org/index.php'less index.htmlcurl http://linuxcommand.org/index.phpcurl http://linuxcommand.org/index.php > index.html -
Netcat is a simple tool for network communication.
Let's use it to listen to the port
12345:nc -l 12345Open another terminal and connect to the same port like this:
nc localhost 12345 # on the second terminalNow, any line that you type here is sent and displayed to the other terminal:
Hello networkThe quick brown fox jumped over the internetCheck the other terminal.
Interrupt them with
Ctrl-c.This may not seem very impressive, but instead of
localhostwe could have used a real server name or IP and connect to it remotely. It may be used to check that the TCP port12345on the server is accessible from the client (in case that there is a firewall, for example).For checking a UDP port we can add the option
-uto both of these commands.It can also be used as a simple tool for file transfer:
nc -l 12345 > file.txt # on the first terminalnc -w 3 localhost 12345 < /etc/passwd # on the second terminalls file.txt # on the first terminalcat file.txt # on the first terminalAs another example, let's combine it with
tarto transfer a whole directory:mkdir cptestcd cptestnc -l 12345 | tar xzpf -Switch to the second terminal.
cd testdir
lstar czpf - . | nc -w 3 localhost 12345Switch to the first terminal.
lscd ..rm -rf cptest