This document discusses network configuration and diagnostic tools in Linux. It describes how to view interface configuration and address information using ifconfig and ip addr show. It also covers changing IP and route settings persistently in configuration files and using ifup/ifdown. Tools like ping and traceroute are presented for network diagnostics.
2. Network Devices in LinuxNetwork Devices in Linux
●
lolo
– Loop back deviceLoop back device
– IP address is 127.0.0.1 permanentlyIP address is 127.0.0.1 permanently
●
ethethNN
– Ethernet interfaceEthernet interface
– Device number starting from 0Device number starting from 0
●
wlanwlanNN
– Wireless interfaceWireless interface
– Device number starting from 0Device number starting from 0
4. Display Address InformationDisplay Address Information
●
ip addr showip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state
UNKNOWNUNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host loinet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forevervalid_lft forever preferred_lft forever
inet6 ::1/128 scope hostinet6 ::1/128 scope host
valid_lft forever preferred_lft forevervalid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP qlen 1000state UP qlen 1000
link/ether 00:16:d3:32:ea:dc brd ff:ff:ff:ff:ff:fflink/ether 00:16:d3:32:ea:dc brd ff:ff:ff:ff:ff:ff
inet 192.168.100.57/24 brd 192.168.100.255 scope global eth0inet 192.168.100.57/24 brd 192.168.100.255 scope global eth0
valid_lft forever preferred_lft forevervalid_lft forever preferred_lft forever
inet6 fe80::216:d3ff:fe32:eadc/64 scope linkinet6 fe80::216:d3ff:fe32:eadc/64 scope link
valid_lft forever preferred_lft forevervalid_lft forever preferred_lft forever
5. Display Link InformationDisplay Link Information
●
ip link showip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state
UNKNOWNUNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP qlen 1000state UP qlen 1000
link/ether 00:16:d3:32:ea:dc brd ff:ff:ff:ff:ff:fflink/ether 00:16:d3:32:ea:dc brd ff:ff:ff:ff:ff:ff
7. Display Routing InformationDisplay Routing Information
●
route nroute n
Kernel IP routing tableKernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use IfaceDestination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.100.11 0.0.0.0 UG 0 0 0 eth00.0.0.0 192.168.100.11 0.0.0.0 UG 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 eth0
192.168.100.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0192.168.100.0 0.0.0.0 255.255.255.0 U 1 0 0 eth0
8. Display Routing InformationDisplay Routing Information
●
ip route showip route show
default via 192.168.100.11 dev eth0 proto staticdefault via 192.168.100.11 dev eth0 proto static
169.254.0.0/16 dev eth0 scope link metric 1000169.254.0.0/16 dev eth0 scope link metric 1000
192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.57192.168.100.0/24 dev eth0 proto kernel scope link src 192.168.100.57
metric 1metric 1
9. Display DNS SettingsDisplay DNS Settings
●
cat /etc/resolv.confcat /etc/resolv.conf
cat /etc/resolv.confcat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE
OVERWRITTENOVERWRITTEN
nameserver 192.168.100.11nameserver 192.168.100.11
10. Change IP SettingsChange IP Settings
●
Add IP:Add IP:
– ifconfig eth0:0 IP/MASKifconfig eth0:0 IP/MASK
– ip address add IP/MASK dev eth0ip address add IP/MASK dev eth0
●
Delete IP:Delete IP:
– ifconfig eth0:0 downifconfig eth0:0 down
– ip address del IP/MASK dev eth0ip address del IP/MASK dev eth0
11. Change Route SettingsChange Route Settings
●
Add route:Add route:
– route add net NET/MASK gw GW_IProute add net NET/MASK gw GW_IP
– ip route add NET/MASK via GW_IPip route add NET/MASK via GW_IP
●
Delete route:Delete route:
– route del net NET/MASK gw GW_IProute del net NET/MASK gw GW_IP
– ip route del NET/MASK via GW_IPip route del NET/MASK via GW_IP
13. Persistent IP SettingsPersistent IP Settings
●
Ubuntu:Ubuntu:
vi /etc/network/interfacesvi /etc/network/interfaces
auto loauto lo
iface lo inet loopbackiface lo inet loopback
iface eth0 inet staticiface eth0 inet static
address 192.168.0.2address 192.168.0.2
netmask 255.255.255.0netmask 255.255.255.0
15. DHCP IP SettingsDHCP IP Settings
●
Ubuntu:Ubuntu:
vi /etc/network/interfacesvi /etc/network/interfaces
auto loauto lo
iface lo inet loopbackiface lo inet loopback
auto eth0auto eth0
iface eth0 inet dhcpiface eth0 inet dhcp
16. UsingUsing ifupifup andand ifdownifdown
●
Only to run while settings are stored inOnly to run while settings are stored in
configuration fileconfiguration file
– ifup eth0ifup eth0
Bring up interfaceBring up interface
– ifdown eth0ifdown eth0
Shutdown interfaceShutdown interface
17. Configure Name ResolutionConfigure Name Resolution
●
/etc/hosts/etc/hosts
– Static mappingStatic mapping
127.0.0.1 localhost.localdomain localhost127.0.0.1 localhost.localdomain localhost
192.168.0.1 server1.my.com server1192.168.0.1 server1.my.com server1
●
/etc/resolv.conf/etc/resolv.conf
– DNS serverDNS server
search my.comsearch my.com
nameserver 192.168.0.1nameserver 192.168.0.1
nameserver 8.8.8.8nameserver 8.8.8.8
18. Configure Name ResolutionConfigure Name Resolution
●
/etc/nsswitch/etc/nsswitch
– Resolving orderResolving order
hosts: files dnshosts: files dns
19. Network Diagnostic ToolsNetwork Diagnostic Tools
●
ping hostping host
– Test connection availabilityTest connection availability
– Common optionsCommon options
c c nn : send: send nn packets onlypackets only
w w nn : set dead line in: set dead line in nn secondsseconds
20. Network Diagnostic ToolsNetwork Diagnostic Tools
●
traceroute hosttraceroute host
– Display all routing nods in the routing pathDisplay all routing nods in the routing path
– Common option:Common option:
n n : Skip name resolving: Skip name resolving
●
mtr hostmtr host
– Advanced traceroute toolAdvanced traceroute tool
21. Network Diagnostic ToolsNetwork Diagnostic Tools
●
arp -aarp -a
– Display all entries in ARP cacheDisplay all entries in ARP cache
●
arp IParp IP
– Display specific entry in ARP cacheDisplay specific entry in ARP cache
●
arp -d IParp -d IP
– Delete an entryDelete an entry
●
arp -s IP MACarp -s IP MAC
– Set an entry manuallySet an entry manually
22. Network Diagnostic ToolsNetwork Diagnostic Tools
●
host DOMAIN_NAME [DNS_SERVER]host DOMAIN_NAME [DNS_SERVER]
– Lookup A record of a domain nameLookup A record of a domain name
– Common optionsCommon options
t t : query type: query type
v v : verbose output: verbose output
W W nn : time out in: time out in nn secondsseconds
●
host IP [DNS_SERVER]host IP [DNS_SERVER]
– The reverse DNS lookupThe reverse DNS lookup
23. Network Diagnostic ToolsNetwork Diagnostic Tools
●
dig DOMAIN_NAME [@DNS_SERVER]dig DOMAIN_NAME [@DNS_SERVER]
– Lookup domain name informationLookup domain name information
– Common optionsCommon options
x IP x IP : reverse lookup: reverse lookup
+short +short : short answer: short answer
+trace +trace : trace recursive lookup from root down: trace recursive lookup from root down
24. Network Diagnostic ToolsNetwork Diagnostic Tools
●
whois DOMAIN_NAMEwhois DOMAIN_NAME
– Lookup domain registration informationLookup domain registration information
– Common optionsCommon options
h server h server : specify whois server: specify whois server
25. Network Diagnostic ToolsNetwork Diagnostic Tools
●
netstatnetstat
– Display socket informationDisplay socket information
– Common optionsCommon options
n n : skip domain name lookup: skip domain name lookup
l l : display listening server sockets: display listening server sockets
t t : display TCP sockets: display TCP sockets
u u : display UDP sockets: display UDP sockets
a a : display all sockets: display all sockets
p p : display PID, root only: display PID, root only