Monday, December 19, 2016

Configuring Network III

Configuring IPv4 Parameters


Remember that you need to configure your network interface with four
parameters in order for the system to participate on an IP-based
computer network. These include the following:


• IP address
• Subnet mask
• Default gateway router address
• DNS server address



There are two different ways to do this, as discussed in Table 15-2.




If you want to statically assign IP address parameters to a Linux
system, you can use the ifconfig command. If


ifconfig 


is entered without any options, it displays the current status of all network
interfaces in the system, as shown in Figure 15-10.




NOTE When you run ifconfig, you’ll notice that your system probably
has two or more interfaces listed, not just one. The extra interface
labeled lo is the loopback interface and is usually assigned a special
IP address of 127.0.0.1. This is a virtual interface, not an actual
hardware interface. It’s used for internal communications, for
diagnostics, and so on.




Notice in Figure 15-10 that two network interfaces are displayed:


ens32 and lo.


The ens32 interface is the Ethernet network interface installed in the system.


The lo interface is the local loopback virtual network interface.

The lo interface is required for many Linux services to run properly, so don’t tinker with it.


Notice in Figure 15-10 that ifconfig also displays extensive information about each
network interface. Some of the more important parameters include those
shown in Table 15-3.




In addition to displaying information about a particular network
interface, ifconfig can also configure the network interface with the
IP address parameters discussed earlier. The syntax for using ifconfig
is

ifconfig interface ip_address netmask subnet_mask broadcast broadcast_ address 

For example, suppose I want to assign the ens32
interface an IP address of 192.168.1.1, a subnet mask of
255.255.255.0, and a broadcast address of 192.168.1.255. I would enter


ifconfig ens32 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 

at the shell prompt.


It’s important to remember that this IP address assignment isn’t
persistent. 

If you reboot the system, it will be lost. To make it
persistent, you need to configure a special file in the


/etc/sysconfig/network 

directory.

For example, the file used to configure the Ethernet interface on my system is named


ifcfg-ens32


NOTE On some distributions, this file will be named using the MAC
address of the NIC. For example,


ifcfg-eth-id-00:0c:29:d1:52:d4


would be the configuration file for the Ethernet interface in the system
with a MAC address of 00:0C:29:D1:52:D4, which will be the first
interface if there is only one NIC installed. Other distributions will
name this file using the alias assigned to the interface, such as
eth0, ens1, and so on.




This file is used to configure the interface when the system is
powered on. Sample parameters for this interface are shown here:


openSUSE:~ # cat /etc/sysconfig/network/ifcfg-ens32
BOOTPROTO='dhcp'
BROADCAST=''
ETHTOOL_OPTIONS=''
IPADDR=''
MTU=''
NAME='82545EM Gigabit Ethernet Controller (Copper)'
NETMASK=''
NETWORK=''
REMOTE_IPADDR=''
STARTMODE='auto'
USERCONTROL='no'




Some of the configuration options you can use in this configuration
file are listed in Table 15-4.




The lines for IPADDR, NETMASK, NETWORK, and BROADCAST are not required
if BOOTPROTO is set to “dhcp”.

The

/etc/hostname

file configures your Linux system’s hostname. After making any changes to these files,
you will need to restart your network interface to apply the changes. To
do this, simply enter 


ifdown interface 


followed by


ifup interface


where interface is the alias of the interface, such as ens32.





This is all well and good if you want to use a static address
assignment, but what if you want to get an address dynamically from a
DHCP server? You can configure your network interface to do this using
the


dhclient 


command at the shell prompt. The syntax for using this command is


dhclient interface


For example, you could enter


dhclient ens32


to specify that your interface get its IP address information
dynamically from a DHCP server. This is shown in Figure 15-11.




Notice in Figure 15-11 that the dhclient utility broadcasted a
DHCPREQUEST packet on the ens32 interface. In response, the DHCP
server with an IP address of 10.0.0.1 sent a DHCPACK packet back with
an IP address of 10.10.0.83 that was assigned to the ens32 interface.





Another utility you can use to manage IP addressing on a Linux system
is the ip command. For example, to view your current configuration,
you can enter


ip addr show 


at the shell prompt, as shown here:



openSUSE:/ # ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 brd 127.255.255.255 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP qlen 1000
    link/ether 00:0c:29:b0:9f:b5 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.83/24 brd 10.0.0.255 scope global ens32
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:feb0:9fb5/64 scope link
       valid_lft forever preferred_lft forever



To use the


ip 


command to configure IP addressing parameters, enter


ip addr add ip_address dev interface 


at the shell prompt. For example, to set the IP address assigned to my ens32 network interface to
10.0.0.84, I would enter



ip addr add 10.0.0.84 dev ens32



To remove an IP address from an interface, just enter



ip addr del ip_address dev interface 



at the shell prompt.






You can also use the ip command to disable and enable a network
interface in the system.


To disable an interface, enter


ip link set interface down 


at the shell prompt.


To bring a disabled interface back online, enter



ip link set interface up



at the shell prompt.








In addition to the command-line utilities discussed here, most Linux
distributions provide some kind of graphical interface you can use to
configure your network interfaces. For example, on SUSE Linux, you can
use the Network Settings YaST module to configure your network board
as well as the IP address information assigned to it. This module is
shown in Figure 15-12.








LX0-104 Exam Objectives (S)





No comments:

Post a Comment