centos 网络配置

时间:2022-07-13 18:20:32

centos 网络配置网络配置

-bash-4.1# setup    #如果没有setup命令,可以yum install setuptool -y  也可以安装setup 命令

          http://jingyan.baidu.com/album/25648fc1a303ce9191fd0032.html?picindex=2

-bash-4.1# yum install setuptool -y

centos 网络配置

-bash-4.1# yum install ntsysv -y              #安装系统服务管理 

-bash-4.1# yum install iptables -y              #安装防火墙

-bash-4.1# yum install system-config-securitylevel-tui  -y  #安装setup中配套的防火墙设置

-bash-4.1# yum install system-config-network-tui -y    #安装setup中配套的网络设置 

-bash-4.1#yum install setuptool -y;yum install ntsysv -y;yum install iptables -y;yum install system-config-securitylevel-tui  -y;yum install system-config-network-tui -y;                       #当然也可以一次执行所有的安装命令,只需要用“;”隔开

然后输入自己ip地址,子网掩码,网关等,如果您用图形界面设置了还是没能生效静态ip,请更改文件BOOTPROTO=static

ifconfig -a
ifup etho 启用网0网卡
ifdown eth0 禁用1网卡

[root@centos01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0   #这个文件是自动获取IP ,只需要ONBOOT=yes 是yes即可
DEVICE=eth0
HWADDR=00:0C:29:79:38:BB
TYPE=Ethernet
UUID=31b2e3cb-096e-41a8-a6aa-da6db0935222
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp

[root@centos01 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0c:29:79:38:bb
TYPE=Ethernet
UUID=31b2e3cb-096e-41a8-a6aa-da6db0935222
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none        #也可以BOOTPROTO=static
IPADDR=192.168.1.7
NETMASK=255.255.255.0
DNS2=114.114.114.114
GATEWAY=192.168.1.1
DNS1=202.96.134.133
IPV6INIT=no
USERCTL=no

[root@centos01 ~]# cat /etc/resolv.conf      #dns配配置文件

一张网卡绑定多个IP

[root@hkproxy ~]#vi /etc/sysconfig/network-scripts/ifcfg-eth0:0  #增加一个IP

[root@hkproxy ~]#vi /etc/sysconfig/network-scripts/ifcfg-eth0:1  #增加第二个IP

DEVICE=eth0:0 网卡设备名称
onboot=YES 随机启动
BOOTPROTO=static 静态分配IP
IPADDR=*.*.*.* 要添加的IP地址
NETMASK=255.255.255.0 子网掩码(以实际为准)
GATEWAY=*.*.*.* 路由

[root@hkproxy ~]#vi /etc/sysconfig/network-scripts/ifcfg-eth0-range  #一张网卡增加一个网址范围
DEVICE=eth0
BOOTPROTO=static
IPADDR_START=起始IP
IPADDR_END=结束IP
CLONENUM_START=网卡起始编号
NETMASK=子网掩码
ONBOOT=yes

[root@hkproxy ~]# ll /etc/sysconfig/network-scripts/ifcfg*
-rw-r--r--. 3 root root 262 Jan 30 21:31 /etc/sysconfig/network-scripts/ifcfg-eth0
-rw-r--r--. 1 root root 245 Jan 30 21:38 /etc/sysconfig/network-scripts/ifcfg-eth0:0
-rw-r--r--. 1 root root 244 Jan 30 21:38 /etc/sysconfig/network-scripts/ifcfg-eth0:1
-rw-r--r--. 1 root root 254 Jan 9 2013 /etc/sysconfig/network-scripts/ifcfg-lo

[root@hkproxy ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0:0 #增加第一个IP
DEVICE=eth0:0
HWADDR=00:0c:29:74:9a:fa
TYPE=Ethernet
UUID=8cec13cd-52f5-4a1f-89cf-1dd07ed00c67
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.1.16
NETMASK=255.255.255.0
DNS2=114.114.114.114
DNS1=202.96.234.233
IPV6INIT=no
USERCTL=no

[root@hkproxy ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0:1 #增加第二个IP
DEVICE=eth0:1
HWADDR=00:0c:29:74:9a:fa
TYPE=Ethernet
UUID=8cec13cd-52f5-4a1f-89cf-1dd07ed00c67
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=192.168.1.17
NETMASK=255.255.255.0
DNS2=114.114.114.114
DNS1=202.96.234.233
IPV6INIT=no
SERCTL=no