How to configure ip in linux

王林
Release: 2019-12-27 10:44:46
Original
4776 people have browsed it

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
Copy after login

2. Modify the gateway address

route add default gw 192.168.100.1 dev eth0
Copy after login

3. Modify the DNS

echo “nameserver 8.8.8.8” >> /etc/resolv.conf
Copy after login

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
Copy after login
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 #系统启动时是否激活此设备
Copy after login

2. Modify the gateway address

Modify/etc/sysconfig/networkFile

vi /etc/sysconfig/network
Copy after login
NETWORKING=yes #表示系统是否使用网络,no表示不能使用网络
HOSTNAME=doiido #设置本机的主机名,要和/etc/hosts中设置的主机名相同
GATEWAY=192.168.100.1 #设置网关的IP地址
Copy after login

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.confFile

vi /etc/resolv.conf
Copy after login
nameserver 8.8.8.8 #google域名服务器
nameserver 114.144.114.114 #国内域名服务器
Copy after login

4. Restart the network card

service network restart
Copy after login
正在关闭接口 eth0: [确定]
关闭环回接口: [确定]
弹出环回接口: [确定]
弹出界面 eth0: [确定]
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template