How to configure the IP address

1. Automatically obtain IP

    1.dhclient

    2.ifconfig

    Through this command, you can view the number of network cards and the IPs of the network cards in the system.

    If your Linux has multiple network cards, it will be displayed as eth1, eth2 and so on in Linux

2. Manually configure IP

    If your virtual machine cannot obtain IP automatically, you can only configure it manually. The configuration method is:

    1.vi /etc/sysconfig/network-scripts/ifcfg-eth0

    2. After entering the document, add the last line:

       IPADDR    NETMASK    GATEWAY

    3. After modification, we can see:

       DEVICE=eth0 (set network card 0)

       HWADDR=00:0C:29:F6:31:79 (mac address)

       TYPE=Ethernet (network type Ethernet)

       UUID=e1f47d3b-2e87-44da-acd9-dd714b7102ec (Universal Unique Identification Code)

       ONBOOT=yes (boot start)

       NM_CONTROLLED=yes (yes does not need to restart the network device after modifying the network card to take effect in real time)

       BOOTPROTO=static (network configuration parameter static static dhcp dynamic acquisition none is used when multi-network card binding is not set)

       IPADDR=192.168.1.135 ( IP address )

       NETMASK=255.255.255.0 (subnet mask)

       GATEWAY=192.168.1.1 (gateway, usually the IP of the router)

       DNS1=192.168.1.1 (DNS server)

       DNS2=8.8.8.8 (alternate DNS server)

    4. Restart the network after exiting the editor: service restart

    5. Test whether it can be pinged

3. When eth0 cannot be found

    1. Linux uses the configuration file /etc/network/interfaces to load the network card.

       In the default configuration, it instructs Linux to automatically find the eth0 network card and assign an IP automatically.

       However, when the MAC address of the virtual network card is changed, the network card is not eth0 in Linux, but eth1 or other values.

       Therefore it will not be found. In the existing system, which network cards are available, you can use the following command to check: ifconfig -a.

     2. In Linux, there is also a configuration file: /etc/udev/rules.d/70-persistent-net.rules.

      After opening this configuration file, you will find that all network cards found by Linux are listed, including historical ones.

     1 Modify the files under interfaces. Replace it with the eth0 device.

     2 Delete the rules file.

     Going with Option 2 is simple and easy. Then restart the system and run ifconfig at this time. You will find two network devices, eth0 and lo.

     Of course, we don’t need to delete the rules file, just replace the file about eth1 with eth0

Supongo que te gusta

Origin blog.csdn.net/TTmanghe/article/details/131107726
Recomendado
Clasificación