The server version of centos is installed in the Virtual Machine for hadoop-related experiments. Centos for server does not have a desktop environment by default, and eth0 is not enabled by default. We need to manually start the network.
Key configurations
Network and host name configuration: Vim/etc/sysconfig/network.
The configuration file is as follows:
Networking = yes # Use Network hostname = centos # Set Host Name
Nic configuration: Vim/etc/sysconfig/network-scripts/ifcfg-eth0
Eth0 indicates the first Nic. The configuration is described as follows:
Device = eth0 # corresponding to the first Nic type = ethernetonboot = yes # whether to run nm_controlled = yesbootproto = static # use a static IP address instead of an IP address allocated by DHCP. The static IP address is configured here, if it is DHCP, simply change the configuration below DHCP to ignore it. Defroute = yesipv4_failure_fatal = yesipv6init = noname = "system eth0" # Name: hwaddr = 00: 50: 56: 94: 04: 3C # It must correspond to the MAC address (/etc/udev/Rules) of etho. d/70-persistent-net.rules) peerdns = yespeerroutes = yesipaddr = 192.168.1.40 # specify the local IP address netmask = 255.255.255.0 # specify the subnet mask gateway = 192.168.1.1 # specify the Gateway
DNS-related configuration (you can select the row configuration. Generally, the network environment is OK and does not need to be configured separately): Vim/etc/resolv. conf
Nameserver 8.8.8.8 # Google's DNS server nameserver xx. xx # backup DNS server nameserver 192.168.1.1 # specify the DNS server specified on the router
Test
Restart the network service through service network restart and use ifconfig to check whether IP Address Allocation is normal.
Centos network configuration (terminal environment)