Centos network configuration

Source: Internet
Author: User
[Modify IP address] 1. use the Setup command to enter the graphical interface, enter NetworkConfiguration and EditDevice as prompted, set IPAs prompted 2. directly edit the file to modify vietcsysconfignetwork-scriptsifc [modify IP address]
1. use the Setup command

Run the setup command to enter the graphic interface. enter Network Configuration and Edit Device as prompted. set the IP address as prompted.

2. directly edit the file and modify it.

# Vi/etc/sysconfig/network-scripts/ifcfg-eth0

The ifcfg-eth0 here is the corresponding Nic profile


Configuration items in the file:
DEVICE = eth0 # describe the DEVICE alias for the NIC, for example, it is eth0 in the ifcfg-eth0 file
BOOTPROTO = static # set the way for the NIC to obtain the IP address. the possible options are static, dhcp, or bootp, which respectively correspond to the IP address specified by the static state and the IP address obtained through the dhcp protocol, IP addresses obtained through the bootp protocol
BROADCAST = 192.168.0.255 # corresponding subnet BROADCAST address
HWADDR = 00: 07: E9: 05: E8: B4 # physical address of the corresponding Nic
IPADDR = 12.168.1.2 # If you set the method for obtaining the IP address from the NIC to static, This field specifies the IP address of the NIC.
IPV6INIT = no
IPV6_AUTOCONF = no
NETMASK = 255.255.255.0 # network mask corresponding to the network adapter
NETWORK = 192.168.1.0 # NETWORK address of the NIC
ONBOOT = yes # whether to set this network interface when the system starts. if it is set to yes, it is critical to activate this device when the system starts. if you want to enable it, you must set it to yes, otherwise, no matter how it is restarted, it will not work.

Modify Gateway]
1. modify the gateway configuration file of the corresponding Nic
# Vi/etc/sysconfig/network
Configuration items in the file
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, and many system service programs cannot be started)
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)
GATEWAY = 192.168.1.1 (set the IP address of the GATEWAY connected to the local machine. For example, the gateway is 10.0.0.2)
2. Setup command
Use Setup to enter the IP settings. you can configure the gateway for different NICs.

Modify DNS]
1. modify the DNS configuration file of the corresponding Nic
# Vi/etc/resolv. conf
The file may contain:
Nameserver 8.8.8.8 # google domain name server
Nameserver 8.8.4.4 # google domain name server
2. Setup command
In NetworkConfiguration settings, special DNS settings are available.

[Restart network configuration]
# Service network restart
Or
#/Etc/init. d/network restart
→ Modify IP address
Effective immediately:
# Ifconfig eth0 192.168.0.2 netmask 255.255.255.0
Start effective:
Modify/etc/sysconfig/network-scripts/ifcfg-eth0
→ Modify the Gateway's Default Gateway
Effective immediately:
# Route add default gw 192.168.0.1 dev eth0
Start effective:
Modify/etc/sysconfig/network
→ Modify DNS
Modify/etc/resolv. conf
The modification takes effect immediately and starts as well.
→ Modify host name
Effective immediately:
# Hostname centos1
Start effective:
Modify/etc/sysconfig/network



[Configure multiple IP addresses for a single NIC]

1. file
When using the Linux system, we will encounter the problem of configuring multiple IP addresses for a single NIC. if there is no graphical interface under Linux, the configuration is really inconvenient. In the text console, there are netconfig and ifconfig tools in the text console. netconfig is a little more convenient in graphical form, but there is no document, and you can still configure an ip address. However, if you configure multiple IP addresses, you may be confused, only ifconfig can be used
# Ifconfig eth0 192.168.0.1 netmask limit 255.0 up description: up indicates immediate activation
How can I configure multiple IP addresses for a single network adapter eth0? if the ifconfig command is used, only eth0 needs to be changed. change eth0 to eth0: x (x is 0-255, for example, eth0: 0 or eth0: 1). eth0: x is called a virtual network interface and is built on a network interface.
Therefore, you can use the following command to configure multiple ip addresses for a single NIC:
# Ifconfig eth0: 0 192.168.0.1 netmask 255.255.255.0 up
# Ifconfig eth0: 1 192.168.0.2 netmask 255.255.255.0 up
After the ping test is passed, the function of configuring multiple ip addresses for a single NIC is completed.

Note: after the server is restarted, the IP address will change back, so you need to set to automatically activate the IP address setting at startup. The methods are as follows:

First:
Add the above command ifconfig to rc. local, which runs automatically after each server is started.

Second:
Is modeled on/etc/sysconfig/network-scripts/ifcfg-eth0 to add a file according to the name of the network virtual interface,

For example, ifcfg-eth0: 0 or ifcfg-eth0: 1 and so on
Next look at the ifcfg-eth0: 0 file configuration information
DEVICE = eth0: 0 # network virtual interface eth0: 0
ONBOOT = yes # activated at startup
BOOTPROTO = static # use a static IP address
IPADDR = 192.168.0.1 # assign an IP address
NETMASK = 255.255.255.0 # subnet mask

→ Close an ip address
# Ifconfig eth0: 0 down

Multiple IP addresses only need eth0: x, for example, eth0: 1 eth0: 2.

Or restart the service. you can restart/etc/init. d/network restart.

EG: If the NIC is configured with eth0, there should be a file like this:/etc/sysconfig/network-scripts/ifcfg-eth0.

Now we need to configure the second ip address. we can use this file as the basis for modification:
Ifcfg-eth0/etc/sysconfig/network-scripts/ifcfg-eth0/etc/sysconfig/network-scripts/: 1
If you need to configure the second ip address, the corresponding is the ifcfg-eth0: 1
Then edit the file:
Vi/etc/sysconfig/network-scripts/ifcfg-eth0: 1
DEVICE = eth0: 1
BOOTPROTO = static
BROADCAST = 192.168.0.255
IPADDR = 192.168.0.101
NETMASK = 255.255.255.0
NETWORK = 192.168.0.0
ONBOOT = yes

Generally, you only need to modify IPADDR. Then restart the network:
/Etc/init. d/network restart
Run ifconfig to see that the IP address of the new configuration takes effect.
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.