Set IP address under Centos/linux

Source: Internet
Author: User
Tags nameserver

Set IP address under Centos/linux

1: Temporary modification:
1.1: Modify IP Address
# ifconfig Eth0 192.168.100.100

1.2: Modify the gateway address
# route add default GW 192.168.100.1 dev eth0

1.3: Modify DNS
# echo "NameServer 8.8.8.8" >>/etc/resolv.conf

This time will be able to surf the internet, the IP address of the Internet is 192.168.100.100, the gateway address is 192.168.100.1. However, such a setting is temporary, once the network card restart or restart the server, in addition to 1.3 of other operations will be restored, such a way only suitable for temporary IP modification, want to permanently modify the network card configuration file, you need to modify the corresponding file

2: Permanent modification:
2.1: Modify the IP address
Modify the/etc/sysconfig/network-scripts/ifcfg-eth0 file, if more than one network card, then modify the appropriate network card
# vi/etc/ Sysconfig/network-scripts/ifcfg-eth0
device=eth0                              #网卡对应的设备别名
bootproto=static              & nbsp     #网卡获得ip地址的方式 (default is DHCP, means auto get)
hwaddr=00:07:e9:05:e8:b4    #网卡MAC地址 (Physical address)
Ipaddr= 192.168.100.100          #IP地址
netmask=255.255.255.0          #子网掩码 &NBSP
onboot=yes                            &NBS P #系统启动时是否激活此设备


2.2: Modify the gateway address
Modify the/etc/sysconfig/network file
# vi/etc/sysconfig/network
Networking=yes #表示系统是否使用网络, no means network is not available
Hostname=doiido #设置本机的主机名 to be the same as the host name set in/etc/hosts
gateway=192.168.100.1 #设置网关的IP地址

You can ping the IP address at this time, but you cannot ping the domain name, so you need to modify the DNS

2.3: Modify DNS
Modify the/etc/resolv.conf file
# vi/etc/resolv.conf
NameServer 8.8.8.8 #google域名服务器
NameServer 114.144.114.114 #国内域名服务器

2.4: Restart the NIC
# Service Network Restart
Shutting down interface eth0: [OK]
Close Loopback interface: [OK]
Eject loopback interface: [OK]
Popup interface eth0: [OK]

This time, the system will be able to surf the internet properly.

#注: In fact, the gateway address and DNS can also be written in Ifcfg-eth0, but for the sake of specification, write them apart

Set IP address under Centos/linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.