To set a static IP address for a machine under Linux:
The code is as follows:
Vim/etc/sysconfig/network-scripts/ifcfg-eth0
Modify the contents of this file in the following form:
The code is as follows:
# Intel Corporation 82541GI Gigabit Ethernet Controller
Device=eth0
Bootproto=static #为静态的
Hwaddr=00:15:17:b2:dc:b5
Onboot=yes
ipaddr=10.20.134.199 #这个是设置的静态IP地址
netmask=255.255.254.0
gateway=10.20.134.1 #网关
After modification, you need to restart the network for the change to take effect:
The code is as follows:
/etc/init.d/network restart
Automatically obtain dynamic IP address mode:
The code is as follows:
Vim/etc/sysconfig/network-scripts/ifcfg-eth1
The contents are as follows:
The code is as follows:
# Intel Corporation 82566dm-2 Gigabit Network Connection
Device=eth1
Bootproto=dhcp #动态获取IP
Hwaddr=00:15:17:b2:dc:b7
Onboot=no
To run the command:
The code is as follows:
Dhclient eth1
Automatically get dynamic IP address
You can view the assigned IP address by: ifconfig.
The code is as follows:
Vim/etc/resolv.conf
is used to define the following four items
nameserver #定义DNS服务器的IP地址, the most important
Domain #定义本地域名
Search #定义域名的搜索列表
sortlist #对返回的域名进行排序