Configuring Basic Networking
LPIC-1 [ Yaser Rahmati | یاسر رحمتی ]
Last updated
Was this helpful?
LPIC-1 [ Yaser Rahmati | یاسر رحمتی ]
Last updated
Was this helpful?
Computer networking is how we get data from one computer system to another.
To help simplify things, computer networks are often described as layered systems.
Different layers play different roles in the process of getting the data from one network device to another.
Network models :
OSI
TCP/IP
The physical layer consists of the hardware required to connect your Linux system to the network.
Copper cables
Fiber-optic cables
Faster speed
Longer distance
Small office and home network
Using radio signals to transmit the data between the network device and network access point
Controls how data is sent between connected network device both in :
local network
across Internet
To connect a Linux system to an IP network you will need 4 pieces of information :
IP
Hostname
Default Router
Netmask
In an IP network, each network device is assigned a unique 32-bit
address.
Dotted-decimal notation :
IP addresses are split into four 8-bit values
, represented by decimal numbers, with a period
between each value.
IP addresses are split into 2 sections :
network address
All devices on the same physical network have the same network address.
host address
Each device on the same network must have a unique host address.
Specific subnetwork ranges are reserved for private IP networks :
Class
First IP
Last IP
A
10.0.0.0
10.255.255.255
B
172.16.0.0
172.31.255.255
C
192.168.0.0
192.168.255.255
With all of these IP addresses, it can be impossible trying to remember just what servers have what addresses.
The Domain Name Server
(DNS) assigns a name to hosts on the network
With DNS, each network address is assigned a domain name (such as linux.org
) and each host in the network is assigned a unique host name
HOST.Domain : shadrach.example.org
To connect different physical networks together you can use a router
Usually, a network will contain a single router to forward packets to an upper-level network. This is called default router
or default gateway
.
Example :
Item
IP
Host Address
192.168.20.5
Netmask
255.255.255.0
Default Gateway
192.168.20.1
Distinguishes between the network and host address portions
Using 1 bit to show which bits of the 32-bit IP address are used by the network and 0 bits to show which bits represent the host address
Class
Default Subnet Mask
Network Bits
A
255.0.0.0
8
B
255.255.0.0
16
C
255.255.255.0
24
Dynamic Host Configuration Protocol
With DHCP, the client communicates with a DHCP server on the network using a temporary address
Each time the client reboots, it may receive a different IP address
The DHCP server can tells the client :
IP address
Netmask address
Default gateway
DNS server
The transport layer helps get the data to the correct application contained on the host by using ports
Two common transport protocols are used in the IP networking world :
Transmission Control Protocol (TCP)
User Datagram Protocol (UDP)
TCP
UDP
Secure
Insecure
Connection-oriented
Connection-less
Slow
Fast
Guaranteed transmission
Not guarantee
Used by critical application
Used by real-time application
Flow control
No flow control
20 bits header
8 bits header
Acknowledgment mechanism
None acknowledgment
3-way handshake (SYN, SYN_ACK, ACK)
No handshake
This is where the network programs process the data sent across the network and then return a result
Most network applications behave using the client/server paradigm
/etc/hosts
/etc/resolv.conf
/etc/sysconfig/network
/etc/sysconfig/network-scripts/ifcfg-interface-name
There are 5 pieces of information you need to configure in Linux system :
The host address
The network subnet address
The default router
The system host name
A DNS server address for resolving host names
Manually editing network configuration files
Using a graphical tool included with your Linux distribution
Using command-line tools
Different distribution uses different configuration files to define the network settings :
Distribution
File / Directory
Debian-based
/etc/network/interfaces file
Red Hat-based
/etc/sysconfig/network-scripts directory
OpenSUSE
/etc/sysconfig/network file
Assumption : Red Hat-based Distribution
The file name format of the network interface configuration file is /etc/sysconfig/network-scripts/ifcfg-#
.
You'll need to define the network settings in 2 separate files :
First. The first file defines the network
and netmask addresses
in a file named after the network interface name (such as ens33
)
TYPE=device_type: The type of network interface device
BOOTPROTO=protocol: Where protocol is one of the following:
none: No boot-time protocol is used.
bootp: Use BOOTP (bootstrap protocol).
dhcp: Use DHCP (Dynamic Host Configuration Protocol).
ONBOOT=answer: Where answer is one of the following:
yes: This interface is activated at boot time.
: This interface is not activated at boot time.
HWADDR=MAC-address: The hardware address of the Ethernet device
IPADDRN=address: The IPv4 address assigned to the interface
PREFIXN=N: Length of the IPv4 netmask value
GATEWAYN=address: The IPv4 gateway address assigned to the interface. Because an interface can be associated with several combinations of IP address, network mask prefix length, and gateway address, these are numbered starting from 0.
DNSN=address: The address of the Domain Name Servers (DNS)
DOMAIN=DNS_search_domain: The DNS search domain
Second. The second file required is the network file, which defines the host name
and default gateway
.
To permanently change the static host name, change the HOSTNAME directive in the /etc/sysconfig/network
file. For example:
For this option, you must have Desktop
installed on your CentOS system. Now, login to your CentOS Desktop
system and open settings
windows on your machine as showing in the below screen.
In the left sidebar click on the Network
tab. After that click icon to open setting for your systems network interface as shown in the below screen.
Here is the IP address
of your desktop system.
NetworkManager Tools
Legacy Tools
Application or Tool
Description
nmcli
A command-line tool which enables users and scripts to interact with NetworkManager. Note that nmcli
can be used on systems without a GUI such as servers to control all aspects of NetworkManager. It has the same functionality as GUI tools.
nmtui
A simple curses-based text user interface (TUI) for NetworkManager
The nmtui tool is used in a terminal window.
It is contained in the NetworkManager-tui
package, but it is not installed along with NetworkManager by default.
To install NetworkManager-tui
To verify that NetworkManager is running :
Start the nmtui
tool:
The text user interface appears.
Press enter after choosing ” Edit a connection”. Now you can see all network interfaces, choose one and click “Edit“.
Choose “Automatic” in IPv4 CONFIGURATION.
Choose Automatic Connect check box.
Press OK and quit Network manager.
Now Restart network service by typing below command.
Choose “Manual” in IPv4 CONFIGURATION.
Add IP Address with Subnet , Gateway and DNS server .
Choose Automatic Connect check box.
Press OK and quit Network manager.
Now Restart network service by typing below command.
ethtool
ifconfig
iwconfig
route
ip
Displays Ethernet settings for a network interface
The ifconfig
command has been deprecated and thus missing by default on CentOS Linux.
Using yum
command install net-tools
package:
The ifconfig
command is now available.
Display information of all network interfaces
View network settings
of specific interface
How to enable
an network interface
How to assign a IP address
to network interface
How to assign a netmask
to network interface
How to assign a broadcast
to network interface
How to assign a IP
, netmask
and broadcast
to network interface
How to enable promiscuous mode
What happens 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.
How to disable promiscuous mode
The route
command can show or change the routing system. As you saw on default gateway section, routing is responsible to send your packets to their correct destination. For checking the current route you can issue
and for temporary adding a default route, youc an do:
Most of the legacy command-line network tools have been replaced with the newer iproute2
package.
The main utility in the iproute2
package is ip
command.
The ip command is more robust than the old ifconfig command.
Display the current network settings :
Specify the host address and netmask values for the interface :
Set the default router
for network interface
Make the network interface active :
As you saw, we were able to set the DNS configuration in network interface config files. But this is not the only way. There is another file which contains this data: /etc/resolv.conf
.
Website : www.yaser-rahmati.ir
Instagram : https://www.instagram.com/yaser.rahmati/
Linkedin : https://www.linkedin.com/in/yaserrahmati/