Set or modify network configurations in CentOS (IP & amp; gateway & amp; DNS)

Source: Internet
Author: User
Tags domain name server

Set or modify network configurations (IP & gateway & DNS) in CentOS)
CentOS IP address Modification

# Ifconfig eth0 192.168.1.80

In this way, the IP address is changed192.168.1.80 (if you find that the network cannot be connected, you may need to change the gateway and DNS, which will be mentioned later), but after you restart the system or network adapter, it will still change back to the original address. This modification method only applies to temporary IP address modification. To make a permanent modification, you must modify/Etc/sysconfig/network-scripts/ifcfg-eth0 this file, the main content of this file is as follows (you can manually add items not in your file ):

[Python] view plaincopy
  1. # Vi/etc/sysconfig/network-scripts/ifcfg-eth0
  2. DEVICE = eth0 # describe the DEVICE alias corresponding to the NIC
  3. BOOTPROTO = static # Set the way for the NIC to obtain the IP address. The options can be static, dhcp, or bootp.
  4. BROADCAST = 192.168.1.255 # corresponding subnet BROADCAST address
  5. HWADDR = 00: 07: E9: 05: E8: B4 # physical address of the corresponding Nic
  6. IPADDR = 12.168.1.80 # This field is required only when the NIC is set to static.
  7. NETMASK = 255.255.255.0 # network mask corresponding to the network adapter
  8. NETWORK = 192.168.1.0 # The NETWORK address corresponding to the NIC, that is, the NETWORK segment to which the ENI belongs
  9. ONBOOT = yes # whether to set this network interface when the system starts. If it is set to yes, the device is activated when the system starts.

Modify Gateway

# Route add default gw 192.168.1.1 dev eth0

In this way, the gateway is changed192.168.1.1. This modification is only temporary. After you restart the system or network card, it will change back to the original gateway. To make a permanent modification, you must modify/Etc/sysconfig/network. The main content of this file is as follows (you can manually add items that are not in your file ):

[Python] view plaincopy
  1. # Vi/etc/sysconfig/network
  2. NETWORKING = yes # indicates whether the system uses the network, which is generally set to yes. If it is set to no, the network cannot be used.
  3. HOSTNAME = centos # Set the Host Name of the local machine. The host name set here must correspond to the host name set in/etc/hosts.
  4. GATEWAY = 192.168.1.1 # Set the IP address of the GATEWAY connected to the local machine.

* ********* After the above files are modified, You need to restart the NIC to take effect:# Service network restart********

Modify DNS

After all the above changes, when you ping a domain name, it is certainly not available, but the corresponding IP address is the same, then we need to modify the DNS. Modify DNS by modifying/Etc/resolv. conf file:

[Python] view plaincopy
  1. # Vi/etc/resolv. conf
  2. Nameserver8.8.8.8 # google Domain Name Server
  3. Nameserver8.8.4.4 # google Domain Name Server

Summary

Through all the above settings, the system should be able to access the Internet.

If you have multiple NICs, you only need to write one copy in the same way as eth0.

If the system is built on a virtual machine, select the 'Bridge adapt' connection when setting the network of the virtual machine.

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.