Centos network configuration method (manual setting and automatic retrieval)

Source: Internet
Author: User
Tags nameserver

Centos network configuration method (manual setting and automatic retrieval)

I don't know why the network has been very slow recently, but it is still disconnected. When the network is disconnected, the LAN cannot be connected. After I manually set the ip address, I can, I am speechless. The following are two ways to set up network connections. before setting up network connections, you must back up the data. Especially for new users, if there are too many changes, you will also be confused, so you must back up a file before modifying it.

1. Modify the file to set the network connection

1. automatically obtain the IP address

It is related to Automatically Obtaining the root 4 files.

A),/etc/sysconfig/network-scripts/ifcfg-eth0

[Zhangy @ localhost network-scripts] $ cat ifcfg-eth0

# Marvell Technology Group Ltd. 88E8039 PCI-E Fast Ethernet Controller

DEVICE = eth0 // started by eth0

BOOTPROTO = dhcp // the IP address is automatically obtained, static is a fixed IP address, and none is manual.

HWADDR = 00: 16: D3: A2: F6: 09 // physical address of the NIC

IPV6INIT = yes // whether IP6 is supported

IPV6_AUTOCONF = yes // whether IP6 is automatically configured

ONBOOT = yes // whether the network interface is valid at startup

B),/etc/sysconfig/network

[Zhangy @ localhost network-scripts] $ cat/etc/sysconfig/network

NETWORKING = yes // whether the Network is available

NETWORKING_IPV6 = yes

HOSTNAME = localhost. localdomain // host name. The host name is configured in/etc/hosts.

C),/etc/hosts

[Zhangy @ localhost network-scripts] $ cat/etc/hosts

# Do not remove the following line, or various programs

# That require network functionality will fail.

In 127.0.0.1localhost.localdomainlocalhost // root/etc/resolv. conf, search must correspond to: localhost. localdomain

: 1 localhost6.localdomain6 localhost6

D),/etc/resolv. conf

[Zhangy @ localhost network-scripts] $ cat/etc/resolv. conf

; Generated by/sbin/dhclient-script

Nameserver 192.168.1.1 // IP address of the DNS server

Searchlocaldomain // search for the domain name to be found, which is set in/etc/hosts

2. manually set

You only need to manually modify three files.

A),/etc/sysconfig/network

[Zhangy @ localhost network-scripts] $ cat/etc/sysconfig/network

NETWORKING = yes

NETWORKING_IPV6 = yes

# HOSTNAME = localhost. localdomain // Why Should I comment out the host name? Generally, the host name or domain name is resolved first, and then the DNS

GATEWAY = 192.168.1.1 // Add the GATEWAY

B),/etc/sysconfig/network-scripts/ifcfg-eth0

[Zhangy @ localhost network-scripts] $ cat ifcfg-eth0

# Marvell Technology Group Ltd. 88E8039 PCI-E Fast Ethernet Controller

DEVICE = eth0

BOOTPROTO = none // start manually

BROADCAST = 192.168.1.255

HWADDR = 00: 16: D3: A2: F6: 09

IPADDR = 192.168.1.108 // set the IP address

NETMASK = 255.255.255.0 // Subnet Mask

NETWORK = 192.168.1.0

IPV6INIT = yes

IPV6_AUTOCONF = yes

ONBOOT = yes

TYPE = Ethernet // network TYPE

C),/etc/resolv. conf

[Zhangy @ localhost network-scripts] $ cat/etc/resolv. conf

#; Generated by/sbin/dhclient-script

# Nameserver 192.168.1.1

# Search localdomain

Nameserver 116.228.111.118 // Add the primary DNS

Nameserver 180.168.20.18 // Add DNS

Ii. Command Methods

Netconfig is a network management tool. After RH is installed, netconfig will appear in the system. Although centos evolved from RH, no. But it doesn't matter. We may install it ourselves.

[Zhangy @ localhost download] $ wget ftp://ftp.nluug.nl/pub/ OS /Linux/distr/CentOS/5.0/ OS /i386/CentOS/netconfig-0.8.24-1.2.2.1.i386.rpm

[Zhangy @ localhost download] $ rpm-ivh netconfig-0.8.24-1.2.2.1.i386.rpm

Error: can't create transaction lock on/var/lib/rpm/_ db.000

[Zhangy @ localhost download] $ su root // do not forget to use the root account. Otherwise, the above error will be reported.

Password:

[Root @ localhost download] # rpm-ivh netconfig-0.8.24-1.2.2.1.i386.rpm

Preparing... ######################################## ### [100%]

1: netconfig ####################################### #### [100%]

[Root @ localhost download] # whereis netconfig // check where netconfig is located

Netconfig:/usr/sbin/netconfig

Copy codeThe Code is as follows:
[Root @ localhost] # netconfig -- help
-- Bootproto = (dhcp | bootp | none) Boot protocol to use // obtain the IP address. dhcp is self-built, bootp is fixed, and none is manual.
-- Gateway = STRING Network gateway // specify the gateway
-- Ip = string ip address // specify the ip address
-- Nameserver = STRING Nameserver // specify DNS
-- Netmask = STRING Netmask // specify the subnet mask
-- Hostname = STRING Hostname // specify the Host Name
-- Domain = STRING Domain name // specifies the domain name
-D, -- device = STRING Network device // specify the Network device
-- Nodns No DNS lookups // No DNS query
-- Hwaddr = STRING Ethernet hardware address // specify the physical address of the NIC
-- Description = STRING Description of the device // description
Help options:
-?, -- Help Show this help message
-- Usage Display brief usage message

1. automatically obtain the IP address

[Root @ localhost download] #/usr/sbin/netconfig-d eth0 -- bootproto = dhcp

2. manually set the IP address

[Root @ localhost download] #/usr/sbin/netconfig-d eth0 -- bootproto = none -- ip = 192.168.1.108 -- netmask = 255.255.255.0 -- gateway = 192.168.1.1 -- nameserver = 116.228.111.118

Iii. Problems Encountered during configuration

1. Restarting the network does not work.

After the service network restart is restarted, the network still cannot be connected. I can confirm that the configuration is correct. Just restart the computer.

2, when backing up the ifcfg-eth0 file to pay attention, do not carry ifcfg-eth0 before

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.