Network¶
Tools & Commands¶
60 Linux Networking commands and scripts¶
Click to visit page useful link
Top 20 tools¶
01. iftop
02. vnstat
03. iptraf
04. monitorix
05. bmon
06. darkstat
07. iperf
08. cbm
09. nload
10. htop
11. slurm
12. tcptrack
13. nethogs
14. speedmeter
speedometer -l -r wlan0 -t wlan0 -m $(( 1024 *1024* 3 / 2 ))
15. sar
apt install sysstat
sar -n DEV 1 --iface=eth0
16. glances
17. ifstat
18. bpytop
19. nmon
Proxy¶
export all_proxy="socks://172.22.132.33:9090/"
install pip package via proxy:
pip3 install pysocks --proxy socks5://172.22.132.33:9090
Real Example for gitlab:
export HTTPS_PROXY=mprxy:mprxy@<remote-ip-addr>:3128
vnstat¶
A database for show usage according to date and time (Tx/Rx/Total)
ssh¶
ssh config¶
To enable a password-less connection
ssh 2 ssh¶
Jump SSH¶
scp¶
Copy the file "foobar.txt" from a remote host to the local host
Copy the file "foobar.txt" from the local host to a remote host
Copy the directory "foo" from the local host to a remote host's directory "bar"
Copy the file "foobar.txt" from remote host "rh1.edu" to remote host "rh2.edu"
Copying the files "foo.txt" and "bar.txt" from the local host to your home directory on the remote host
Copy the file "foobar.txt" from the local host to a remote host using a different port number
Copy multiple files from the remote host to your current directory on the local host
scp username@remotehost.edu:/some/remote/directory/\{a,b,c\} .
scp username@remotehost.edu:~/\{foo.txt,bar.txt\} .
scp Performance¶
By default, SCP uses the Triple-DES cipher to encrypt the data being sent. Using the Blowfish cipher has been shown to increase speed. This can be done by using the option -c blowfish in the command line.
It is often suggested that the -C option for compression should also be used to increase speed. The effect of compression, however, will only significantly increase speed if your connection is very slow.
rsync¶
Access via remote shell
Example:
Set up rsync via a different port
ip command (iproute2 pckg)¶
Install 'ip' linux package
ip addr¶
Note: You can use a instead of addr
🧠 Concept
ip addr (short for ip address) is used to view, add, or remove IP addresses on your network interfaces.
It operates at Layer 3 (Network Layer) — managing how your system is identified on the network.
Show all assigned IP addresses
Add a new IP address
➡️ Adds an additional address (can have multiple per interface).
Remove an IP address
Replace (set) an IP address
This automatically removes the old one if it exists.
Bring an interface up or down (quick link control)
Flush (remove) all addresses from an interface
🔍 Scopes¶
| Scope | Meaning |
|---|---|
global |
Reachable from outside the host |
link |
Valid only on the local network segment |
host |
Valid only within the local system (loopback) |
ip route¶
Note: You can use r instead of route
🧠 Concept:
ip route is used to view and manage the kernel’s routing table — basically, the rules Linux uses to decide where to send outgoing packets.
Show the routing table
Add a new route manually
sudo ip route add default via {GATEWAYIP} [dev {INTERFACE-NAME}]
sudo ip route add 10.10.0.0/16 via 192.168.100.254 dev ens160
➡️ Any packet to 10.10.x.x will be sent to gateway 192.168.100.254.
Delete a route
Temporarily remove internet access (for testing)
Change the default gateway
🧠 Tip: Check where traffic goes
➡️ Any packet to 10.10.x.x will be sent to gateway 192.168.100.254.
ip link¶
ip link is part of the iproute2 toolset in Linux, and it’s used to show and configure network interfaces (links).
It works at Layer 2 (Data Link Layer) — meaning it deals with the physical or virtual network interfaces themselves, not with IP addresses or routing.
Show Links
Show all network interfaces
Bring an interface up
Bring an interface down
Change an interface’s MTU, Reduces the maximum frame size (useful in tunnels or VPNs).
Change an interface’s MAC address
Show a specific interface
Up & Down Interface
ip neighbor¶
See which devices your system has interacted with
Delete a specific entry from the ARP cache
Flush the entire ARP cache
Add a static ARP entry manually (less common)
Note: You can use n instead of neigh
Subnet Mask¶
Calculate the subnet mask from the IP address
Range of Private Networks
route (net-tools)¶
see all routes:
Add new route:
telnet¶
Check the connection between two machines:
nmap¶
Scan port on the host(s)
See nmap Cheat Sheet
fuser¶
kill open port directly
Kernel IP forwarding¶
Temporarily Enable/Disable IP Forwarding¶
Manually
via sysctl
Permanently Enable Forwarding¶
To ensure forwarding settings persist between reboots
change the value and uncomment the line
T-Shoot Tools¶
1. log file¶
2. Commands¶
arp -n
ping gateway
ss -l list, -m memory
netstat netstat -tulpen
traceroute google.com
mtr google.com
tcpflow -c \<port-number\>
3. Interactive trouble¶
4. Expert & DNS resolve Commands¶
nmap -v google.com, nmap 192.168.1.1/24 80
host google.com
nslookup google.com
dig google.com
lsof -i
5. tcpdump¶
-i any every port
-p 1234 port 1234
-D all available interfaces
-w file.pcap write to file
-r file.pcap read from file
-c count of captured package
dst ip packet route TO address
src ip packet route FROM address
-A read packet data
ngrep -t -W byline port 8088 -d any
tcpdump -i any -nn -s 0 -w k8s_port_6443.pcap port 6443 and host 172.16.2.10