The basic method of modifying IP address, gateway and DNS under Linux system

Source: Internet
Author: User

temporarily modify IP address, gateway, hostname, DNS, effective immediately, no restart (after restart)

1. Modify Host Name


#hostname Slyar

2. Modify the IP address (eth0 is the NIC name)


#ifconfig eth0 192.168.1.5 netmask 255.255.255.0

3. Modify the default gateway (Eth0 is the NIC name)


#route add default GW 192.168.1.1 Dev eth0

4. Modify DNS


#vim/etc/resolv.conf

The CentOS (RedHat) command line permanently modifies the IP address, gateway, DNS

The command line permanently modifies the IP address, gateway, and DNS

1. Modify the IP address
First check your host card number and name, related information under/etc/sysconfig/network-scripts/.

You can see that I have 2 network card, the first block is the Ethernet physical network card, number 0, if you have more than one network card, the number is 0, 1, 2, 3 ...; the second network card is a loopback network card, generally do not need to set.

Use VIM to edit you need to set the IP network card, here I can only modify Ifcfg-eth0, look at the graph, not much explanation, the previous state is Bootproto set to DHCP when the wording.


Vim/etc/sysconfig/network-scripts/ifcfg-eth0


Device=eth0 #网卡名称
Bootproto=static #获取ip的方式 (STATIC/DHCP/BOOTP), not explained
hwaddr=00:0c:29:b5:b2:69 #MAC地址
ipaddr=12.168.1.5 #IP地址
netmask=255.255.255.0 #子网掩码
network=192.168.1.0 #网络地址
broadcast=192.168.0.255 #广播地址
Nboot=yes #启动设备

2. Modify the Gateway


Vim/etc/sysconfig/network

Add a gateway Message


gateway=192.168.1.1

3. Modify DNS


Vim/etc/resolv.conf

Add DNS information to


NameServer 192.168.1.1

4. Reload the network configuration


/etc/init.d/network restart

The basic method of modifying IP address, gateway and DNS under Linux system

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.