Lecture-5_Networking Commands
Lecture-5_Networking Commands
3
Understanding Network Devices in Linux
(continued)
• Kernel modules can be loaded or unloaded while
Linux is running
• /dev/eth0
• First Ethernet card installed on system
• Media Access Control (MAC) address
• Unique address assigned by Ethernet card manufacturer
4
Understanding Network Devices in Linux
(continued)
5
Understanding Network Devices in Linux
(continued)
• arp command
• Display ARP cache
• Mapping of IP addresses to hardware addresses
• Used mainly for troubleshooting network connectivity
• Refreshed frequently
6
Configuration NIC IP address
• NIC: Network Interface Card
• Use “ipconfig” command to determine IP address, interface devices, and
change NIC configuration
• Any device use symbol to determine
• eth0: Ethernet device number 0
• eth1: ethernet device number 1
• lo : local loopback device
• Wlan0 : Wireless lan 0
7
Determining NIC IP Address
[root@tmp]# ifconfig -a
9
Permanent IP configuration
10
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]# 11
Getting the IP Address Using DHCP
[root@tmp]# cd /etc/sysconfig/network-scripts
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
[root@network-scripts]#
12
Activate config change
• After change, the values in the configuration files for the NIC you
must deactivate and activate it for the modifications to take effect.
• The ifdown and ifup commands can be used to do this:
13
Multiple IP Addresses on a Single NIC(1)
[root@tmp]# ifconfig –a
• Shutting down the main interface also shuts down all its aliases
too. Aliases can be shutdown independently of other interfaces 16
The process for creating an IP alias
• Admin should also create a /etc/sysconfig/network-
scripts/ifcfg-wlan0:0 file
• so that the aliases will all be managed automatically
with the ifup and ifdown commands
DEVICE=wlan0:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.99
NETMASK=255.255.255.0
19
How to Change Default Gateway
[root@tmp]# route add default gw 192.168.1.1 wlan0
NETWORKING=yes
HOSTNAME=bigboy
GATEWAY=192.168.1.1 20
How to Delete a Route
21
Linux router
22
Configuring IP Forwarding
• For your Linux server to become a router, you have
to enable packet forwarding.
• In simple terms packet forwarding enables packets
to flow through the Linux server from one network
to another.
• The Linux kernel configuration parameter to activate
this is named net.ipv4.ip_forward and can be found
in the file /etc/sysctl.conf.
• Remove the "#" from the line related to packet
forwarding.
23
/etc/sysctl.conf changing
Before: # Disables packet forwarding
net.ipv4.ip_forward=0
net.ipv4.ip_forward=1
192.168.1.101 smallfry
• You can also add aliases to the end of the line which enable
you to refer to the server using other names.
• Here we have set it up so that smallfry can also be accessed
using the names tiny and littleguy.
27
Using ping to Test Network Connectivity
• The Linux ping command will send continuous pings, once a second, until
stopped with a Ctrl-C.
• Here is an example of a successful ping to the server bigboy at 192.168.1.100
[root@smallfry tmp]# ping 192.168.1.101
PING 192.168.1.101 (192.168.1.101) from 192.168.1.100 : 56(84) bytes of data.
64 bytes from 192.168.1.101: icmp_seq=1 ttl=128 time=3.95 ms
64 bytes from 192.168.1.101: icmp_seq=2 ttl=128 time=7.07 ms
64 bytes from 192.168.1.101: icmp_seq=3 ttl=128 time=4.46 ms
64 bytes from 192.168.1.101: icmp_seq=4 ttl=128 time=4.31 ms
[root@smallfry tmp]# 28
Using ping to Test Network Connectivity
•Most servers will respond to a ping query it
becomes a very handy tool.
•A lack of response could be due to:
• A server with that IP address doesn't exist
• The server has been configured not to respond to pings
• A firewall or router along the network path is blocking ICMP
traffic
• You have incorrect routing. Check the routes and subnet masks
on both the local and remote servers and all routers in
between.
• Either the source or destination device having an incorrect IP
address or subnet mask.
29
Configuring Networking with Command-line
Utilities
• ifconfig command
• Set up network configuration in Linux kernel
• Parameters include:
• Network interface
• IP address assigned to interface
• Network mask
• Syntax
• ifconfig device ip_address netmask address broadcast address
• $ ifconfig eth0
30
Configuring Networking with Command-line
Utilities (continued)
31
Configuring Networking with Command-line
Utilities (continued)
• View status of interface: ifconfig eth0
• Stop Ethernet interface: ifconfig eth0 down
• Start Ethernet interface: ifconfig eth0 up
• Routing table tells networking software where to send packets that are not
part of local network
• A real example of configuring an Ethernet card at the command line might
look like this:
• # ifconfig eth0 192.168 . 100.1 netmask 255.255.255.0 broadcast 192. 168.100.255
32
Configuring Networking with Command-line
Utilities (continued)
• route command
• View or configure routing table within kernel
• Executed at boot time when networking initialized
• Output information for addresses
• 192.168.100.0 (eth0 IP address)
• 127.0.0.0
• Other
33
Configuring Networking with Command-line
Utilities (continued)
• Route command output
• Destination – Ref
• Gateway – Use
• Genmask – Iface
• Flags
• Add route example:
• route add -net 192.168.100.0 netmask 255.255.255.0 dev eth0
• This command adds a default gateway route,
• # route add default gw 192.168.100.5
34
Configuring Networking with Command-line
Utilities (continued)
• service command
• Start or stop networking
• Relies on script /etc/rc.d/init.d/network
• /etc/sysconfig/networking/devices configuration directory
• Contains file for each network device
• ifcfg-eth0 file
• Used by /etc/rc.d/init.d/network script
• As it executes ifconfig and route commands
35
Changing IP Address/Other Parameters
36
Configuring Networking with Command-line
Utilities (continued)
• ifup and ifdown scripts manage single interface, rather than all network
interfaces
• Example:
• # ./ifup eth0
• # ./ifdown eth0
• Some systems have two or more physical network devices
37
Configuring Networking with Command-line
Utilities (continued)
• IP forwarding
• Allows packets to be passed between network interfaces
• Required for any router
• To enable:
• # echo 1 > /proc/sys/net/ipv4/ip_forward
38
Thanks
Q&A