Wednesday, April 9, 2008

关于redhat系列与debian系列的网络基本配置

以前弱,只知道用system-config-network这个GUI来设置网络,又烂又慢.
最近因为要远程配置cluster,因此研究了一下静态配置的方法,其实也很简单.
但是由于cluster用的系统是fedora,但自己机器上是ubuntu,发觉有些不一样,做个笔记对比下.
PS.由于ubuntu是debian系列的,我猜想debian也是差不多的
而网上查到redhat与fedora的配置文件的确是一样的.

以下仅涉及以太网的IP,netmask,gateway,broadcast设置.
以及dns,resolve配置.

共同的设置:
1. DNS服务器 resolv.conf
均使用/etc/resolv.conf ( 注意是resolv不是resolve )来配置DNS服务器
它的格式如下:
nameserver IP
nameserver IP
...

很简单
另外还有不少的option,不过发觉似乎没什么会用到的,就没有细看了.

2.静态主机名查询表 hosts
均使用/etc/hosts来记录静态的主机名,别名以及IP. 在windows下则是 %windows%\system32\hosts( 如果没记错 )
格式如下:
IP    hostname alias[,alias...]
其中这行必须存在,用于定义换回接口的地址以及域名
127.0.0.1       localhost.localdomain   localhost       localhost

一个IP对应一个主机名以及多个别名.使用hostname可以设置以及修改域名

不同的设置

1.
ubuntu中,/etc/hostname 用来定义本机主机名,用于启动时供启动脚本读取设定.
而redhat系列貌似没有这个文件,在hostname的手册页中介绍到
       The host name is usually set once at system startup in /etc/rc.d/rc.inet1 or /etc/init.d/boot (normally by reading the contents  of  a
       file which contains the host name, e.g.  /etc/hostname).
另外在网上看到的介绍是:
在/etc/sysconfig/network中进行设定.然而我在ubuntu中貌似找不到类似的文件.

我在启动脚本看到,/etc/rc.d/rc.sysvinit里含有设定的语句.
而在/etc/rc.d/rc.local中看到用nisdomainname来设定nis的domainname.

2.
ubuntu中/etc/network/interfaces用来定义各个interface的IP等设定
----------------------
我的机器该文件如下:
auto lo
iface lo inet loopback
address 127.0.0.1
netmask 255.0.0.0


iface eth0 inet static
address 172.18.34.177
netmask 255.255.252.0
gateway 172.18.35.254

auto eth0

iface eth1 inet dhcp

----------------------
其中auto表示机器启动时自动up.
iface一项定义该界面的具体参数,
static表示静态地址而dhcp表示...就是dhcp拉 -.-
其中static又应包括address,netmask,gateway.

而在redhat中,使用/etc/sysconfig/network-scripts/ifcfg-ethn来设定
其中ethn可替换为网卡名.在某台机器上看到内容ifcfg-eth0如下:
# Intel Corporation 82562ET/EZ/GT/GZ - PRO/100 VE (LOM) Ethernet Controller
DEVICE=eth0
BOOTPROTO=none
BROADCAST=202.116.76.255
IPADDR=202.116.76.163
NETMASK=255.255.255.0
NETWORK=202.116.76.0
ONBOOT=yes
GATEWAY=202.116.76.1
TYPE=Ethernet
USERCTL=no
IPV6INIT=no
PEERDNS=yes

需要填写的field其实跟ubuntu大同小异.
同时注意到,ifup和ifdown script都在这里.它们就是通过读取这里的设定来完成interface的up & down的.
但是

另外我还注意到,在/etc/sysconfig/networking中:
devices文件夹包含ifcfg-eth{0,1},其中eth0和eth1是已有的网络设备.
这两个文件与/etc/sysconfig/network-scripts的两个文件inode相同,说明是硬链接.

而在profiles/default中包含有:
hosts  ifcfg-eth0  ifcfg-eth1  network  resolv.conf
几个文件,其中hosts,network,resolv.conf分别为/etc/hosts,/etc/sysconfig/network,/etc/resolv.conf的硬链接.
而ifcfg-eth{0,1}与上面提到的是硬链接.




No comments: