Description: Candidates should be able to configure a network device to be able to connect to a local, wired or wireless, and a wide-area network. This objective includes being able to communicate between various subnets within a single network including both IPv4 and IPv6 networks.
Key Knowledge Areas:
Utilities to configure and manipulate ethernet network interfaces
Configuring basic access to wireless networks
Terms and Utilities:
ip
ifconfig
route
arp
iw
iwconfig
iwlist
In this course we spend some time on Networking tools and review what we has learned. As more experienced we become, less time we spend on troubleshooting.But before that lets draw a big picture.
Network Configuration
Network Configuration in Linux can be pretty confusing. In linux, Network setting can be done in different levels and each level has different tools.
here we mostly talk about run time configuration tools although some times we say where to save configs to make it persistence.
ifconfig
ifconfig (interface configuration) is a utility to configure, manage and query network interface parameters via command line interface or in a system configuration scripts.
The ifconfig command is used for displaying current network configuration information, setting up an ip address, netmask or broadcast address to an network interface, creating an alias for network interface, setting up hardware address and enable or disable network interfaces.
Now let have a review over ifconfig command family:
mapping multiple IP addresses to a single NIC:
When we setup a system's network, we usually assign one IP address per network interface(NIC).This serves as the primary address.But in some situations we might require set multiple IP addresses on a machine. Good news is that we don not need one NIC per IP Address. Linux is capable of mapping multiple IP addresses to a single NIC by using IP aliasing
note that alias network address in same sub-net mask. For example, if your eth0 network ip address is 192.168.10.63, then alias ip address must be 192.168.10.64
root@server1:~# ifconfig ens33:0 down
root@server1:~# ifconfig ens33:0
ens33:0 Link encap:Ethernet HWaddr 00:0c:29:03:64:0d
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
note that alias network address in same sub-net mask. For example, if your eth0 network ip address is 192.168.10.63, then alias ip address must be 192.168.10.64.
Promiscuous Mode
In normal mode, when a packet received by a network card, it verifies that the packet belongs to itself. If not, it drops the packet normally, but in the promiscuous mode is used to accept all the packets that flows through the network card.
The mtu argument set the maximum transmission unit to an interface. The MTU allows us to set the limit size of packets that are transmitted on an interface. The MTU able to handle maximum number of octets to an interface in one single transaction. Not all network interfaces supports MTU settings.
ip addr add 192.168.10.64/24 dev eth0 label eth0:1
ip addr del 192.168.10.64/24 dev eth0 label eth0:1
Plaese note that if we use ip addr add command to add alias, ifconfig doesn't show any thing because it doesn't know how to deal with it.
set promiscuous
ip link set eth0 promisc on
ip link set eth0 promisc off
Change MTU
ip link set dev eth0 mtu 1600
Do not Forget all chnages that we have made are not persistence, To make it persistence modify /etc/sysconfig/network-scripts/ifcfg-eth0 in RedHat or edit /etc/network/interfaces in debian based systems.
route
route command shows and manipulate ip routing table.
root@server1:~# route --help
Usage: route [-nNvee] [-FC] [<AF>] List kernel routing tables
route [-v] [-FC] {add|del|flush} ... Modify routing table for AF.
route {-h|--help} [<AF>] Detailed usage syntax for specified AF.
route {-V|--version} Display version/author and exit.
-v, --verbose be verbose
-n, --numeric don't resolve names
-e, --extend display other/more information
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
<AF>=Use '-A <af>' or '--<af>'; default: inet
List of possible address families (which support routing):
inet (DARPA Internet) inet6 (IPv6) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) ipx (Novell IPX) ddp (Appletalk DDP)
x25 (CCITT X.25)
root@server1:~# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.10.2 0.0.0.0 UG 100 0 0 ens33
link-local * 255.255.0.0 U 1000 0 0 ens33
192.168.10.0 * 255.255.255.0 U 100 0 0 ens33
By default route command displays the host name in its output. We can request it to display the numerical IP address using -n option:
root@server1:~# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.10.2 0.0.0.0 UG 100 0 0 ens33
169.254.0.0 0.0.0.0 255.255.0.0 U 1000 0 0 ens33
192.168.10.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
There are two more commands to see routing table:
root@server1:~# netstat -rn
Kernel IP routing table
Destination Gateway Genmask Flags MSS Window irtt Iface
0.0.0.0 192.168.10.2 0.0.0.0 UG 0 0 0 ens33
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 ens33
192.168.10.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
root@server1:~# ip route show
default via 192.168.10.2 dev ens33 proto static metric 100
169.254.0.0/16 dev ens33 scope link metric 1000
192.168.10.0/24 dev ens33 proto kernel scope link src 192.168.10.152 metric 100
Some other commands:
To make route setting persistence, We need to edit /etc/sysconfig/network-scripts/route-eth0 file to define static routes for eth0 interface. In Debian based systems we need to edit /etc/network/interfaces file.
arp
How dose it work ? When an incoming packet destined for a host machine on a LAN arrives at a gateway, the gateway asks the ARP program to find a physical host or MAC address that matches the IP address. The ARP program looks in the ARP cache and, if it finds the address, provides it so that the packet can be converted to the right packet length and format and sent to the machine. If no entry is found for the IP address, ARP broadcasts a request packet in a special format to all the machines on the LAN to see if one machine knows that it has that IP address associated with it. A machine that recognizes the IP address as its own returns a reply so indicating. ARP updates the ARP cache for future reference and then sends the packet to the MAC address that replied.
root@server1:~# arp --help
Usage:
arp [-vn] [<HW>] [-i <if>] [-a] [<hostname>] <-Display ARP cache
arp [-v] [-i <if>] -d <host> [pub] <-Delete ARP entry
arp [-vnD] [<HW>] [-i <if>] -f [<filename>] <-Add entry from file
arp [-v] [<HW>] [-i <if>] -s <host> <hwaddr> [temp] <-Add entry
arp [-v] [<HW>] [-i <if>] -Ds <host> <if> [netmask <nm>] pub <-''-
-a display (all) hosts in alternative (BSD) style
-s, --set set a new ARP entry
-d, --delete delete a specified entry
-v, --verbose be verbose
-n, --numeric don't resolve names
-i, --device specify network interface (e.g. eth0)
-D, --use-device read <hwaddr> from given device
-A, -p, --protocol specify protocol family
-f, --file read new entries from file or from /etc/ethers
<HW>=Use '-H <hw>' to specify hardware address type. Default: ether
List of possible hardware types (which support ARP):
ash (Ash) ether (Ethernet) ax25 (AMPR AX.25)
netrom (AMPR NET/ROM) rose (AMPR ROSE) arcnet (ARCnet)
dlci (Frame Relay DLCI) fddi (Fiber Distributed Data Interface) hippi (HIPPI)
irda (IrLAP) x25 (generic X.25) eui64 (Generic EUI-64)
root@server1:~# arp -a
? (192.168.10.2) at 00:50:56:fb:49:80 [ether] on ens33
? (192.168.10.254) at 00:50:56:e5:83:09 [ether] on ens33
root@server1:~# ping 192.168.10.151
PING 192.168.10.151 (192.168.10.151) 56(84) bytes of data.
64 bytes from 192.168.10.151: icmp_seq=1 ttl=64 time=0.704 ms
64 bytes from 192.168.10.151: icmp_seq=2 ttl=64 time=1.47 ms
64 bytes from 192.168.10.151: icmp_seq=3 ttl=64 time=1.28 ms
^C
--- 192.168.10.151 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2029ms
rtt min/avg/max/mdev = 0.704/1.156/1.475/0.328 ms
root@server1:~# arp -a
? (192.168.10.2) at 00:50:56:fb:49:80 [ether] on ens33
? (192.168.10.254) at 00:50:56:e5:83:09 [ether] on ens33
? (192.168.10.151) at 00:0c:29:40:b1:ca [ether] on ens33
some usefull switches:
arp is replace byip n command.
Its good to know that all Network Switches has some thing like MAC Address table to work.
iw,iwconfig,iwlist
Linux has great tools for working with wireless connections, iw is a new configuration utility for wireless devices which supports all new drivers that have been added to the kernel recently. iw is still under development. The old tool is iwconfig which is deprecated but still exist.
In computer networks computers talk to each other with their physical addresses in fact. Address Resolution Protocol (ARP) is used to convert ip address to the physical address.
ifconfig command
Description
ifconfig
Display all Active Network Interfaces.
ifconfig -a
Display all Network Interfaces (weather Enable or Disable)
ifconfig eth0
Network Settings of specific Interface
ifconfig eth0 [up/down]
Enable or Disable a Network Interface
ifconfig eth0 192.168.10.63
Assign an IP Address to Network Interface
ifconfig eth0 netmask 255.255.255.0
Assign a Networkmask to Network Interface
ifconfig broadcast 192.168.10.255
Assign a Broadcast to Network Interface
ifconfig eth0 192.168.10.63 netmask 255.255.255.0
Set both IP Address and netmask at the
ifconfig eth0 hw ether AA:BB:CC:DD:EE:FF
Change the mac Address of Network Interface
ip command
Description
ip addr show
Display deep information about all Network Interfaces
ip a show eth0
Network Settings of specific Network Interface
ip link set eth0 [up/down]
Disable / Enbale Network interface
ip addr add 192.168.10.63/24 dev eth0
Assign IP Address to specific Network Interface
ip addr del 192.168.10.63/24 dev eth0
Remove IP Address
ip addr add broadcast 192.168.10.255 dev eth0
Add Broadcast Address to the Network Interface
ip link set mtu 1500 dev eth0 AA:BB:CC:DD:EE:FF
Set mac Address of Network Interface
ip link set mtu 1500 dev eth0
Set MTU of Network Device
route command
Description
route add default gw 192.168.10.2
Add Default Gateway, use "del" to Delete
route add -net 192.168.10.0/24 gw 192.168.10.2 dev eth0
Add Route, use "del" for Deleting , "dev" can be ommited