Home >Operation and Maintenance >Linux Operation and Maintenance >How to configure ip in linux
Setting the IP address under CentOS/Linux
1. Temporary modification:
1. Modify the IP address
ifconfig eth0 192.168.100.100
2. Modify the gateway address
route add default gw 192.168.100.1 dev eth0
3. Modify the DNS
echo “nameserver 8.8.8.8” >> /etc/resolv.conf
You can now access the Internet. The IP address for accessing the Internet is 192.168.100.100
. The gateway The address is 192.168.100.1
. However, this setting is temporary. Once the network card is restarted or the server is restarted, except for the DNS modification operation, everything else will be restored. This method is only suitable for temporary IP modification. If you want to permanently modify the network card configuration file, you need to modify the corresponding file.
Free learning video tutorial sharing: linux video tutorial
2. Permanent modification
1. Modify IP address
Modify/etc/sysconfig/network-scripts/ifcfg-eth0
file. If there are multiple network cards, modify the corresponding network card
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0 #网卡对应的设备别名 BOOTPROTO=static #网卡获得ip地址的方式(默认为dhcp,表示自动获取) HWADDR=00:07:E9:05:E8:B4 #网卡MAC地址(物理地址) IPADDR=192.168.100.100 #IP地址 NETMASK=255.255.255.0 #子网掩码 ONBOOT=yes #系统启动时是否激活此设备
2. Modify the gateway address
Modify/etc/sysconfig/network
File
vi /etc/sysconfig/network
NETWORKING=yes #表示系统是否使用网络,no表示不能使用网络 HOSTNAME=doiido #设置本机的主机名,要和/etc/hosts中设置的主机名相同 GATEWAY=192.168.100.1 #设置网关的IP地址
At this time, the IP address can be pinged, but the domain name cannot be pinged, so the DNS needs to be modified.
3. Modify DNS
Modify /etc/resolv.conf
File
vi /etc/resolv.conf
nameserver 8.8.8.8 #google域名服务器 nameserver 114.144.114.114 #国内域名服务器
4. Restart the network card
service network restart
正在关闭接口 eth0: [确定] 关闭环回接口: [确定] 弹出环回接口: [确定] 弹出界面 eth0: [确定]
At this time , the system can access the Internet normally.
Related article tutorial sharing: linux tutorial
The above is the detailed content of How to configure ip in linux. For more information, please follow other related articles on the PHP Chinese website!