Linux 14 - Network Operations in Linux

By Sheldon L Published at 2020-04-29 Updated at 2020-04-20


IP Addresses

IPv4 and IPv6

Classful Network Address

IP Address Allocation

Name Resolution

cat /etc/hosts
cat /etc/resolv.conf

host linuxfoundation.org
nslookup linuxfoundation.org
dig linuxfoundation.org

Network Configuration and Tools

Network Configuration Files

# Debian
ls -l /etc/network/

# Fedora and SUSE
ls -l /etc/sysconfig/network/

nmtui
nmcli

Network Interfaces

ifconfig enp4s0f2          # enp4s0f2 is the network interface
ip -s link show enp4s0f2
ip address show enp4s0f2

The ip Utility

/sbin/ip addr show   # interface config, similar to `ifconfig`
/sbin/ip route show  # routing table, similar to `route`
ip --brief addr show # more brief

ifconfig             # interface config
route -n             # routing table

ping

ping -c [n] [address]  # ping [n] times

route

route -n  # Show current routing table
ip route  # Show current routing table

route add -net [address] # Add static route
ip route add [address]   # Add static route

route del -net [address] # Delete static route
ip route del [address]   # Delete static route

traceroute

traceroute [address]

More Networking Tools

Networking Tools Description
ethtool Queries network interfaces and can also set various parameters such as the speed
netstat Displays all active connections and routing tables. Useful for monitoring performance and troubleshooting
nmap Scans open ports on a network. Important for security analysis
tcpdump Dumps network traffic for analysis
iptraf Monitors network traffic in text mode
mtr Combines functionality of ping and traceroute and gives a continuously updated display
dig Tests DNS workings. A good replacement for host and nslookup
sudo ethtool [interface]
netstat -r
nmap -sP 192.168.0.0/24

Browsers, wget and curl

Graphical and Non-Graphical Browsers

wget and curl

wget [url]  # download

curl [url]  # read
curl -o [saved_file_name] [url] # download

Network Troubleshooting

/sbin/ifconfig
ip addr show

# if IP address not show
# one of these can restart network
sudo systemctl restart NetworkManager
sudo systemctl restart network
sudo service NetworkManager restart
sudo service network restart
# and try to refresh dhcp address
sudo dhclient [interface]
hostname
sudo ping -c 3 google.com
host google.com
# nameserver conf: /etc/resolv.conf
# If you wanted to override that you could do:
host google.com 8.8.8.8 # google nameserver
# Note that there is another file, /etc/hosts,
# where you can associate names with IP addresses,
# which is used before the DNS server is consulted.
# This is most useful for specifying nodes on your local network.

dig google.com
# Tracing the route to one of the public name server
sudo traceroute 8.8.8.8

# default gate way
ip route show

sudo mtr --report-cycles 3 8.8.8.8  # an enhanced version of traceroute

Transfering Files

FTP

ftp [address]  # such as ftp.gnu.org
# Hint: The user name for anonymous FTP site is `anonymous`.
# most anonymous FTP sites require you to supply a password, but it does not matter what you give!
> ls
> get [file]   # such as fwelcome.msg
> quit

ssh and scp

# ssh
ssh [user]@[address]
# scp
scp [localfile] <user@remotesystem>:/home/user/
scp -r [localfolder] <user@remotesystem>:/home/user/