CentOS modifies network settings and solves the problem that some commands do not exist.

Source: Internet
Author: User
Tags domain name server nameserver

1. Modify the IP address of CentOS

Modify the configuration file of the corresponding Nic IP Address
# Vi/etc/sysconfig/network-scripts/ifcfg-eth0

Modify the following content

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, the device is activated when the system starts.

Ii. CentOS gateway Modification

Modify the gateway configuration file of the corresponding Nic

[Root @ centos] # vi/etc/sysconfig/network

Modify the following content

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)

3. Modify DNS in CentOS

Modify the DNS configuration file of the corresponding Nic
# Vi/etc/resolv. conf

Modify the following content

Nameserver 8.8.8.8 # google Domain Name Server

Nameserver 8.8.4.4 # google Domain Name Server

4. 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 Gateway 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

Centos cannot find ifconfig commands or other commands

The system prompts that some commands do not exist.


Use #/sbin/ifconfig
Cause: the default environment variable is incorrect.
Echo $ PATH is executed for common users and root users respectively. Four addresses are missing in PATH:/sbin:/usr/local/sbin: /usr/kerberos/sbin
Ifconfig is exactly in/sbin. You can also open/etc/profile to find that there are no environment variables for/sbin.
Run vi/etc/profile
Add the following statement at the end of the file:


PATH = $ PATH:/sbin # append the/sbin directory after the PATH variable
Export PATH = $ PATH:/sbin # Set the variable to global


Save and exit.
Modify/home/user/. bash_profile and add/sbin:/usr/local/sbin:/usr/kerberos/sbin to the PATH.
After the modification, run the command: .. bash_profile. You can also log off or restart it to make the modified content take effect.
Then sudo ifconfig, and then OK.

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.