This post has a collection of Linux commands for networking. There are basic linux network commands, advanced linux network commands and some centos network configuration commands, but I’ve tried to keep it to the point.
When setting up a new redhat / centos based machine, the first thing you will need to do once the system is installed is to configure the network.
Navigate to the network configuration directory – /etc/sysconfig/network-scripts
Assuming you are configuring interface eth0 [though this will work for any networking device that is found by the kernel]
The easiest way to configure your network device is to enable dhcp.
Check that the ifcfg-eth0 file has (among other things):
If you need to configure a static IP for the device:
IPADDR=xxx.xxx.xxx.xxx #[replace the xxx with your ipaddress]
NETMASK=xxx.xxx.xxx.xxx #[replace xxx with your netmask]
GATEWAY=xxx.xxx.xxx.xxx #[replace xxx with your gateway (router) device's ip address so that your traffic can be routed correctly]
You can also add in the DNS servers to query in this file:
Linux commands for networking – Basic commands. These are a few basic linux network commands that I use day-to day to find information on servers, check if they are responding, find which name-servers they use, and which entries they have in their DNS records
nslookup is used to query DNS to find ip addresses belonging to domain names
to query DNS to find ip addresses belonging to domain names, using a specified nameserver (in this case 18.104.22.168)
nslookup 22.214.171.124 google.com
Advanced Linux Network Commands
Linux commands for networking – Advanced commands. These are more advanced commands that I don’t need to use that often, but when I need to find information on a large number of hosts, or active IP addresses, or map my home network, this is what I use for Linux network host discovery – there are various ways to find the hosts in your network using command-line commands.
For the following, it is assumed that:
192.168.1.0/24 is your whole network
192.168.1.255 is your broadcast address
Replace with your own values (you can find these with ifconfig)
scapy arp ping
you can run an arp-ping in scapy
The fastest way to discover hosts on a local ethernet network is to use the ARP Ping method. This can help you address ip conflicts by listing all the hosts on your network (incase you have multiple hosts connected to your network trying to use the same ip address)
Use the -b flag to ping your broadcast address, and listen for all the replies
ping -b 192.168.1.255
-sn (No port scan)
This option tells Nmap not to do a port scan after host discovery, and only print out the available hosts that responded to the host discovery probes. This is often known as a “ping scan”. It can easily be used to count available machines on a network or monitor server availability. This is often called a ping sweep, and is more reliable than pinging the broadcast address because many hosts do not reply to broadcast queries.
In previous releases of Nmap, -sn was known as -sP.