Linux Network Configuration and Troubleshooting Commands
NIC: Network Interface Card
Use “ipconfig” command to determine IP address, interface
devices, and change NIC configuration
Determining NIC IP
Address
[root@tmp]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 00:08:C7:10:74:A8
BROADCAST MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Interrupt:11 Base address:0x1820
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:787 errors:0 dropped:0 overruns:0 frame:0
TX packets:787 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:82644 (80.7 Kb) TX bytes:82644 (80.7 Kb)
Changing IP Address
We could give this eth0 interface an IP address using the
ifconfig command.
[root@tmp]# ifconfig eth0 10.0.0.1 netmask
255.255.255.0 up
The "up" at
the end of the command activates the interface.
To make this
permanent each time boot up by add this command in /etc/rc.local file which is
run at the end of every reboot.
Permanent IP
configuration
Fedora Linux also makes life a little easier with interface
configuration files located in the /etc/sysconfig/network-scripts directory.
Interface eth0 has a file called ifcfg-eth0, eth1 uses
ifcfg-eth1, and so on.
Admin can place your IP address information in these files
File formats for
network-scripts
root@network-scripts]# less ifcfg-eth0
DEVICE=eth0
IPADDR=192.168.1.100
NETMASK=255.255.255.0
BOOTPROTO=static
ONBOOT=yes
#
# The following settings are optional
#
BROADCAST=192.168.1.255
NETWORK=192.168.1.0
[root@network-scripts]#
Activate config
change
After change the values in the configuration files for the NIC
you have to deactivate and activate it for the modifications to take effect.
The ifdown and ifup
commands can be used to do this:
[root@network-scripts]# ifdown
eth0
[root@network-scripts]# ifup eth0
1. ifconfig
ifconfig (interface
configurator) command is use to
¡
initialize an interface,
¡
assign IP Address to interface
¡
and
enable or disable interface on demand.
With this
command you can view
¡
IP Address
¡
and Hardware / MAC
address assign to interface
¡
and also MTU (Maximum transmission
unit) size.
ifconfig with
interface (eth0) command only shows specific interface details
like IP Address, MAC Address etc.
with -a options
will display all available interface details if it is disable also.
Assigning IP Address and Gateway
Assigning
an IP Address and Gateway to interface on the fly.
The setting
will be removed in case of system reboot.
Enable or Disable Specific Interface
To enable or disable specific Interface, we use example command as follows.
Setting MTU Size
By default MTU size is 1500. We can set
required MTU size with below command. Replace XXXX with
size.
Set Interface in Promiscuous mode
Network interface only received packets belongs to that
particular NIC. If you put interface in promiscuous mode it will
received all the packets. This is very useful to capture packets and analyse
later. For this you may require super user access.
how do I Configure Static IP Address
Internet Protocol (IPv4)?
Assign Static
IP Address to eth0 interface editing configuration file
/etc/network/interfaces to make permanent changes as shown below.
Next, restart network services after entering all the details using the
following command.
How to Remove an IP Address
The following command will remove an assigned IP address from the given interface (eth1).
2. PING Command
PING (Packet
INternet Groper) command is the best way to test connectivity between two
nodes.
Whether it is Local Area Network (LAN) or Wide Area Network (WAN).
Ping use ICMP (Internet Control Message Protocol) to communicate to other devices. You can ping host
name of ip address using below command.
In Linux ping command keep executing until you interrupt.
Ping with -c option exit after N number of request (success or error respond).
3. TRACEROUTE
Command
traceroute is
a network troubleshooting utility which shows number of hops taken to reach
destination
also determine packets travelling path.
Below we are
tracing route to global DNS server IP Address and able to reach
destination also shows path of that packet is travelling.
4. NETSTAT Command
Netstat (Network
Statistic) command display connection info, routing table information etc.
To displays
routing table information use option as -r.
Listing all ports (both TCP and UDP)
using netstat -a option.
Listing
only TCP (Transmission Control Protocol) port connections
using netstat -at.
Listing all active listening ports
connections with netstat -l.
5. DIG Command
Dig (domain
information groper ) is a tool for querying DNS nameservers for
information about host addresses, mail exchanges, nameservers, and related
information.
This command mainly use to troubleshoot DNS related
query.
6. NSLOOKUP
Command
nslookup command
also use to find out DNS related query. The following examples
shows A Record (IP Address) of tecmint.com.
7. ROUTE
Command
route command
also shows and manipulate ip routing table.
To see default routing table in Linux,
type the following command.
Adding, deleting routes and default
Gateway with following commands.
8. HOST Command
host command to find name to IP or IP to name in IPv4 or IPv6 and also query DNS records.
9. ETHTOOL
Command
.
ethtool is a replacement of mii-tool.
It is to view, setting speed and duplex of your Network Interface
Card(NIC).
.
You can set duplex permanently
in /etc/sysconfig/network-scripts/ifcfg-eth0 with ETHTOOL_OPTSvariable.
By : mogtaba altyib
Modification by : Mohammed Bakry PhD