You can get the advice from IT HELP DESK

SYSTEM [LINUX] How to set up and manage the network

Robert
17 Jan 2019
<head>Disk Management, Server Monitoring, System management, server monitoring, server management, system management, system monitoring, </head>

 [LINUX] How to set up and manage the network


Hello ~!

I will explain how to set up and manage the network ~


Let's look at how to set up network information and run network daemons on Linux OS.


1. /etc/sysconfig/network

The file /etc/sysconfig/network is a file that contains settings for the entire Linux system. In general, the items set in the network file are as follows.

  • Network availability
  • Hostname
  • Gateway IP address
  • Interface name to communicate with Gateway


[root@localhost sysconfig]# vi /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=localhost
GATEWAY=192.168.1.1


The hostname is localhost  and the gateway is 192.168.1.1 "


After you change the file, you must reboot the network via the service network restart  command before the changes take effect. 


2. /etc/hosts 

The /etc/hosts file is simply a file that names the IP address.

Most of them are using DNS servers nowadays but they are still useful in networks without a separate name server!


[root@localhost sysconfig]# vi /etc/hosts

127.0.0.1         localhost
::1                   localhost
192.168.1.25    backupSVR


As an example, suppose that the above sample is recorded in the /etc/hosts file

I will connect to the backupSVR host on my Linux machine! It is automatically connected to 192.168.1.25.


3. /etc/resolv.conf 

The /etc/resolv.conf file specifies the IP address of the DNS server.

I explained that I will write IP through /etc/hosts file. But how do I import a domain that is not in the /etc/hosts file?

In general, the procedure for searching for IP in Linux is as follows.

  1. View local cache data
  2. View the /etc/hosts file
  3. DNS lookup

At this time, in order to find a hostname that is not in the /etc/hosts file, the DNS server will ask for the IP address of the hostname

The file that can specify this DNS server is the /etc/resolv.conf file!


[root@localhost sysconfig]# vi /etc/resolv.conf

nameserver 8.8.8.8
nameserver 8.8.4.4


In the above example file, you can see that 8.8.8.8 / 8.8.4.4 two DNS servers are specified.

These two IPs are Google's Public DNS (IPv4) IP addresses.

If you have a DNS server that you use separately, you can do the same.

If the contents change, the network must be restarted via service network restart  command before the changes take effect.  



4. /etc/sysconfig/network-scripts/ifcfg-eth0

The files described above are network settings that are commonly used by the OS.

This file is a file that can assign a name to each network interface, assign an IP, and apply various settings.


The default gateway and other settings above may overlap with the values set in this file,

Please note that in this case, the data recorded in this file take precedence!


[root@localhost sysconfig]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
TYPE=Ethernet
UUID=XXXX-XXXX-XXXX-XXXX-XXXX
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.10.93
NETMASK=255.255.255.0
GATEWAY=192.168.10.1
DNS1 = 168.126.63.1
USERCTL=no
PEERDNS=yes
IPV6INIT=no
HWADDR=XX:XX:XX:XX:XX:XX


The above configuration file is the contents of the ifcfg-eth0 file with the IP address 192.168.1.1 assigned to the eth0 interface, the gateway 192.168.10.1, and the DNS server 168.126.63.1.

Let's take a look at what each line means.


[root @ localhost sysconfig] #  vi /etc/sysconfig/network-scripts/ifcfg-eth0 

## Name of the network interface
 DEVICE = eth0


## Ethernet / bond / Tap is set as the type of network interface. ## Under normal network settings, Ethernet is the default. 

TYPE = Ethernet

## Unique ID of interface
 UUID = XXXX-XXXX-XXXX-XXXX-XXXX

## Enable or disable the interface automatically when booting OS
 ONBOOT = yes

## Allow network setting in GUI mode
 NM_CONTROLLED = yes

## Set the IP grant method. When static IP is set, static
 BOOTPROTO = static

## Specify the IP address of the network interface
 IPADDR = 192.168.10.93

## Specify the subnet mask for the network interface
 NETMASK = 255.255.255.0

## Specify the gateway address to which the network interface will communicate
 GATEWAY = 192.168.10.1

## Specify the DNS address to which the network interface will communicate
 DNS1 = 168.126.63.1

## Whether ordinary users can control their network interfaces
 USERCTL = no

## Whether to use your own DNS. When set to yes, DNS server configuration is required in /etc/resolv.conf
 PEERDNS = yes

## Enable IPv6?
 IPV6INIT = no

## MAC address of the Ethernet card
 HWADDR = XX: XX: XX: XX: XX: XX


5. Run the network daemon 

Unlike Windows, changing network-related settings on Linux does not take effect immediately.

After you make the changes, the changed values will not take effect until you rerun the network daemon.


  •    Network service program: /etc/init.d/network 
    • Run the network service program: /etc/init.d/network.start   
    • Restart the network service program: /etc/init.d/network.restart     
    • Exit the network service program: /etc/init.d/network.stop 


The above command is executed through the network executable file in /etc/init.d

Normally, network binaries are registered with the service.


  • service network start / restart / stop


It can be used in the above form.


Please leave a comment on the question.