Four Methods to Configure Network in Linux

Click the blue text above to follow us

Four Methods to Configure Network in Linux
Four Methods to Configure Network in Linux

Several methods to set up the network:

Four Methods to Configure Network in Linux
1. ifconfig Command
Four Methods to Configure Network in Linux

Usage:

ifconfig [DEVICE]                                          ## View network informationifconfig DEVICE IP netmask NETMASK        ## Set IP address

Temporary effect, will be invalid after restarting the service.

Four Methods to Configure Network in Linux
Four Methods to Configure Network in Linux
2. nm-connection-editor
Four Methods to Configure Network in Linux

A graphical network configuration tool, requires a graphical interface to use.

Four Methods to Configure Network in Linux
Four Methods to Configure Network in Linux

3. nmtui

Four Methods to Configure Network in Linux

Another graphical configuration tool, the difference is that it follows a retro approach and does not require a graphical interface to use.

Switch to non-graphical interface using init 3, and you can open the nmtui network configuration tool with this command.

Edit a connection: Set up a connection, you can add or delete network configurations.

Activate a connection: Activate a connection, you can enable or disable network configurations.

Set system hostname: Set HOSTNAME, set hostname.

Configure a network card to try, as shown: Add —> Ethernet (there are also options for Wifi, Bridge, VLAN, etc.).

Four Methods to Configure Network in Linux

Profile name: Configuration name, use the same name as the network card.

Device: Device name, use network card eth0.

IPv4 configuration: IPv4 configuration, optional automatic, manual, etc., choose Manual for manual configuration.

There is a Show on the right, select to expand.

Addresses: Configure IP address, 10.0.0.10/8, at first glance it seems confusing, IP address configuration usually has a subnet mask, but this one does not have it and cannot be omitted, try writing it this way, /8 represents an eight-bit mask, equal to 255.0.0.0.

Since it is a virtual machine, it only communicates with the physical machine and does not connect to the external network, so DNS and other settings can be left blank for now, move to ok and press enter.

Four Methods to Configure Network in Linux

Exit and check whether the configuration has taken effect.

Four Methods to Configure Network in Linux

Configuration effective, network connected.

Four Methods to Configure Network in Linux

4. Directly create or modify network configuration files

Four Methods to Configure Network in Linux

File location /etc/sysconfig/network-scripts/ifcfg-XXXX

##XXXX is the configuration file name, generally the same as the network card for easy identification, of course, do as you like.

[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0         ## Edit network configuration file     ####DHCP network configuration####NAME=eth0                                               ## Specify the network link name as eth0, personal habit, do as you likeDEVICE=eth0                                             ## Specify the network card name to manageBOOTPROTO=dhcp                                          ## dhcp dynamic acquisition, none and static indicate static networkONBOOT=yes                                              ## Whether to start on boot     ####Static network address configuration####NAME=eth0                                               ## Specify the network link name as eth0, personal habit, do as you likeDEVICE=eth0                                             ## Specify the network card name to manageBOOTPROTO=static                                        ## dhcp dynamic acquisition, none and static indicate static networkONBOOT=yes                                              ## Whether to start on bootIPADDR=10.0.0.10                                        ## Set IP to 10.0.0.10NETMASK=255.0.0.0|PREFIX=8                              ## Subnet mask is 255.0.0.0     GATEWAY=10.0.0.1                                        ## Gateway address, if you need to access the external network setDNS=***.***.***.***                                     ## DNS address, if domain name resolution is needed setPEERDNS=yes|no                                          ## Whether to modify /etc/resolv.conf, no means not to modify####IPADDR, NETMASK, PREFIX, GATEWAY, DNS can be followed by numbers to set multiple groups of IP addresses####Of course, there are more parameters that can be configured, if needed you can check the help document /usr/share/doc/initscripts-*/sysconfig.txt

Domain name resolution:

The hosts file translates easily memorable address names into IP addresses for computer access.

Location of hosts file:/etc/hosts

Format:IP address Host name

The DNS server’s pointing file, the hosts file is a local name resolution file, when we need to access an address not in the hosts file, we need to find the DNS server for resolution.

Location of the file:/etc/resolv.conf

Format:SERVERNAME IP address

There are many other methods to configure the network, such as nmcli command, ip command, etc. Personally, I think the most reliable methods are the ip command and directly modifying the configuration file. Other various network configuration tools may not be reliable when you have no network or no installation source, for example, the ifconfig command is not installed by default in minimal installations of Linux.

Receive Benefits

Four Methods to Configure Network in Linux

Plant a Tree
The best time was 10 years ago
The second best time is now
Learning is the same
Four Methods to Configure Network in Linux

Source: Internet Please delete if infringing

Leave a Comment