2013年6月24日星期一

linux 网络配置

redhat版本

配置文件:
/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE:设备 eth0,eth1...
ONBOOT:系统启动时是否自动启动网卡  YES,NO
BOOTPROTO:获取ip方式  static,auto(?即不用设置)
IPADDR:ip地址
NETMASK:子网掩码
GATEWAY:网关

eg:
DEVICE eth0
ONBOOT YES
BOOTPROTO static
IPADDR 192.168.1.110
NETMASK 255.255.255.0
GATEWAY 192.168.1.1

管理网络设备:
service network start|stop|restart|status

ifup   启动网卡
ifdown 关闭网卡
eg: ifdown eth0 #关闭第1块网卡
    ifup eth0 #启动第一块网卡

配置完成之后,重启网卡:
service network restart



ubuntu版本

配置文件:
/etc/network/interfaces 这里是IP,网关,掩码等配置
/etc/resolv.conf 这个文件保存DNS的有关信息

auto lo
iface lo inet loopback
#回环地址 127.0.0.1

#网卡eth0的配置
auto eth0

#staic 静态IP
iface eth0 inet static
address 192.168.1.110
netmask 255.255.255.0
gateway 192.168.1.1
#network 192.168.3.0
#broadcast 192.168.1.255
#后面两条是网络号和广播号,这个可以由其它信息计算,因此无需设置


还可以配置第二IP(虚拟IP)
auto eth0:1
iface eth0:1 inet static
address 192.168.1.110
netmask 255.255.255.0
#network x.x.x.x
#broadcast x.x.x.x
gateway x.x.x.x


配置DNS:
vi /etc/resolv.conf
nameserver 202.107.117.11

配置主机名:
vi /etc/hostname
主机名默认存在,不需修改

重启网络:
sudo /etc/init.d/networking restart