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

Source: Internet
Author: User

The Linux Command Line permanently modifies the IP address, gateway, and DNS.

1. Modify the IP address

First, check the number and name of your host Nic. The related information is under/etc/sysconfig/network-scripts.

As you can see, I have two NICs. The first is an Ethernet physical NIC with no. 0. If you have multiple NICs, the numbers are 0, 1, 2, and 3 ...; the second ENI is a back-to-ring Eni, which generally does not need to be set.

Use vim to edit the NIC you need to set the IP address, here I can only modify the ifcfg-eth0, see the figure, not much explanation, the previous status is set to DHCP when writing.

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

DEVICE = eth0 # Nic name
BOOTPROTO = static # method for obtaining ip addresses (static/dhcp/bootp)
HWADDR = 00: 0C: 29: B5: B2: 69 # MAC address
IPADDR = 12.168.1.5 # IP Address
NETMASK = 255.255.255.0 # Subnet Mask
NETWORK = 192.168.1.0 # NETWORK address
BROADCAST = 192.168.0.255 # BROADCAST address
NBOOT = yes # Start the device

2. Modify the Gateway

Vim/etc/sysconfig/network

Add a gateway

GATEWAY = 192.168.1.1

3. Modify DNS

Vim/etc/resolv. conf

Add DNS information.

Nameserver 192.168.1.1

4. Reload Network Configuration

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