Linux CentOS6 Network Settings

Linux CentOS6 Network Settings

View IP address

ifconfig        # 查看IP地址

ping baidu.com  # ping 百度

NIC configuration static (fixed) configuration

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

DEVICE=eth0
TYPE=Ethernet
UUID=a8a8a8a8-a8a8-a0a0-0000-000000000000
ONBOOT=yes                # 开启自动启用网络连接
NM_CONTROLLED=no          # 不使用系统界面的网络管理

BOOTPROTO=static          # 静态(固定)配置
HWADDR=AA:00:AA:00:AA:00
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no             # 禁止IPV6
NAME="System eth0"

IPADDR=192.168.0.111    # IP地址
NETMASK=255.255.255.0   # 子网掩码
GATEWAY=192.168.0.1     # 网关
DNS1=192.168.1.1        # 主DNS
DNS2=192.168.0.1        # 备DNS

NIC configuration dynamic (auto-obtained) configuration

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

DEVICE=eth0
TYPE=Ethernet
UUID=a8a8a8a8-a8a8-a0a0-0000-000000000000
ONBOOT=yes
NM_CONTROLLED=no

BOOTPROTO=dhcp            # 动态(自动获取)配置
HWADDR=AA:00:AA:00:AA:00
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"

restart network connection

service network restart  # 重启网络连接

ifconfig                 # 查看IP地址

ping baidu.com           # ping 百度

If not normal check DNS and hostname settings

cat /etc/resolv.conf  # DNS设置

; generated by /sbin/dhclient-script
nameserver 202.106.0.20
nameserver 202.106.196.115

nameserver 192.168.0.1   # 或者直接设置到路由
nameserver 8.8.8.8       # 也可以使用Google的公共DNS服务
nameserver 8.8.4.4       # Google的公共DNS服务

search localhost
cat /etc/sysconfig/network  # hostname设置
NETWORKING=yes
HOSTNAME=localhost.localdomain
#GATEWAY=192.168.0.1

Check hosts settings

cat /etc/hosts  # hosts设置

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

If you don't use IPV6 service, you can stop it

service ip6tables stop   # 停止IPV6服务

chkconfig ip6tables off  # 禁止IPV6开机启动

Linux, as long as there is Xwindows, Linux will use NetworkManager by default to assist in managing network configuration. For configuring the Linux server, we don't need NetworkMananger to configure the network, so turn it off or it will affect the manual network configuration.

You can query the system's self-starting process through chkconfig. NetworkMananger is on the first line. You can see that it will start automatically at run levels 2, 3, 4, and 5 of the Linux system. Just shut it down and stop it without restarting it.

chkconfig | head -1           # 查询系统自启进程

chkconfig NetworkManager off  # 关闭NetworkManager自动启动

service NetworkManager stop   # 关闭NetworkManager守护进程

serivce NetworkManager status # 查询状态

If using a virtual machine, use bridged networking;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326689850&siteId=291194637