Configuration of IPV4 in Linux

Keywords: network vim Windows Linux

The nmcli connection show command enables you to view the identified network card name.

[root@localhost ~]# nmcli connection show
//Name UUID type device   
ens33   f45a714b-7ccc-4e58-9f52-e8a6c3027a15  802-3-ethernet  ens33  
virbr0  32b28b6a-4b00-4e7c-9a41-2217b2c25449  bridge          virbr0 

 

The network card configuration file of the virtual machine is under the path / etc / sysconfig / network scripts /. vincen here is an example of how to configure the ipv4 of the ens33 network card

[root@localhost ~]# cd /etc/sysconfig/network-scripts/  #Path to network card profile
[root@localhost network-scripts]# ls
ifcfg-ens33  ifdown-isdn      ifup          ifup-plip      ifup-tunnel
ifcfg-lo     ifdown-post      ifup-aliases  ifup-plusb     ifup-wireless
ifdown       ifdown-ppp       ifup-bnep     ifup-post      init.ipv6-global
ifdown-bnep  ifdown-routes    ifup-eth      ifup-ppp       network-functions
ifdown-eth   ifdown-sit       ifup-ib       ifup-routes    network-functions-ipv6
ifdown-ib    ifdown-Team      ifup-ippp     ifup-sit
ifdown-ippp  ifdown-TeamPort  ifup-ipv6     ifup-Team
ifdown-ipv6  ifdown-tunnel    ifup-isdn     ifup-TeamPort
[root@localhost network-scripts]# vim ifcfg-ens33 #Modify the configuration of network card ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static                        #The default is dhcp, which is changed to static static allocation
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=f45a714b-7ccc-4e58-9f52-e8a6c3027a15
DEVICE=ens33
ONBOOT=yes                              #The default is no, which is changed to yes to allow the network card to be started
IPADDR=172.25.0.1                       #Add item, add ip 172.25.0.5
PREFIX=16                               #Add item, add subnet mask to 16
GETAWAY=172.25.0.3                      #Add item, the added gateway is 172.25.0.3 (this gateway is based on the IP address of VNnet1 in the network sharing center on Windows)
DNS1=8.8.8.8

 

Restart the network card after configuration

[root@localhost network-scripts]# service network restart   #Restart network card command

 

After the network card is restarted successfully, you can view the name and specific information of the network card through ifconfig command, such as the corresponding IP, subnet mask, gateway and so on. In the virtual machine of vincen, the first network card name (the left most) is ens33, IP (inet) is 172.25.0.5, and netmask is 255.255.0.0

[root@localhost ~]# ifconfig 
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.25.0.1  netmask 255.255.0.0  broadcast 172.25.255.255
        inet6 fe80::9bfb:e5a9:5911:2ed0  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:ad:05:c6  txqueuelen 1000  (Ethernet)
        RX packets 90  bytes 9051 (8.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 88  bytes 12178 (11.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 66  bytes 5676 (5.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 66  bytes 5676 (5.5 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:46:ba:48  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

At this time, the IP of linux has been successfully configured

Posted by Pandolfo on Mon, 06 Jan 2020 14:40:34 -0800