Basic methods of modifying IP address, gateway and DNS under Linux system

Source: Internet
Author: User

Temporarily modify IP address, gateway, host name, DNS, immediately effective, no reboot (failure after reboot)

1. Modify Host Name

The code is as follows:
#hostname Slyar

2. Modify IP address (eth0 is the name of the network card)

The code is as follows:
#ifconfig eth0 192.168.1.5 netmask 255.255.255.0

3. Modify the default gateway (Eth0 is the name of the network card)

The code is as follows:
#route add default GW 192.168.1.1 Dev eth0

4. Modify DNS

The code is as follows:
#vim/etc/resolv.conf

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

The command line permanently modifies IP addresses, gateways, and DNS

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

I can see from the figure that I have 2 network card, the first is 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 edit you need to set IP network card, here I can only modify Ifcfg-eth0, look at the map, not many explanations, the previous state is Bootproto set to DHCP when the writing.

The code is as follows:
Vim/etc/sysconfig/network-scripts/ifcfg-eth0

The code is as follows:

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 Gateway
The code is as follows:
Vim/etc/sysconfig/network
Add a gateway Message
The code is as follows:
gateway=192.168.1.1

3. Modify DNS

The code is as follows:

Vim/etc/resolv.conf
Adding DNS information can

The code is as follows:
NameServer 192.168.1.1

4. Reload Network Configuration

The code is as follows:
/etc/init.d/network restart

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.