2008年(10)
分类: LINUX
2008-05-14 11:50:33
示例环境: OS: FC2 NIC: eth0 host name: fc2 ip: 192.168.0.20/24 default gateway: 192.168.0.254 修改ip地址 即时生效: # ifconfig eth0 192.168.0.20 netmask 255.255.255.0 启动生效: 修改/etc/sysconfig/network-scripts/ifcfg-eth0 修改default gateway 即时生效: # route add default gw 192.168.0.254 启动生效: 修改/etc/sysconfig/network-scripts/ifcfg-eth0 修改dns 修改/etc/resolv.conf 修改后可即时生效,启动同样有效 修改host name 即时生效: # hostname fc2 启动生效: 修改/etc/sysconfig/network 深入研究: 以上各配置文件由于发行版本的差异会有不同,但可以通过分析启动脚本来取得配置文件的详细信息 由于FC2的启动脚本过于繁琐,我下面的例子中分析的是SysV风格的LFS初始化shell脚本: # grep hostname /etc/rc.d/init.d/* 代码: /etc/rc.d/init.d/localnet: echo "Setting hostname to $HOSTNAME..." /etc/rc.d/init.d/localnet: hostname $HOSTNAME /etc/rc.d/init.d/localnet: echo "Hostname is: $(hostname)"可以看出设置hostname使用了/etc/rc.d/init.d/localnet脚本 分析此脚本可以看出相关设置是在/etc/sysconfig/network文件中 请注意实际上相关文件不一定是/etc/rc.d/init.d/localnet和/etc/sysconfig/network,一切取决于个发型版的个性设置,但以上步骤是通用的分析方法。 /etc/rc.d/init.d/localnet: 注意其中的 . /etc/sysconfig/network 代码: #!/bin/bash # Begin $rc_base/init.d/localnet - Loopback device # Based on localnet sysklogd script from LFS-3.1 and earlier. # Based on localnet sysklogd script from LFS-3.1 and earlier. # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org . /etc/sysconfig/rc . $rc_functions . /etc/sysconfig/network case "$1" in start) echo "Bringing up the loopback interface..." ifconfig lo 127.0.0.1 evaluate_retval echo "Setting hostname to $HOSTNAME..." # Based on localnet sysklogd script from LFS-3.1 and earlier. # Rewritten by Gerard Beekmans - gerard@linuxfromscratch.org . /etc/sysconfig/rc . $rc_functions . /etc/sysconfig/network case "$1" in start) echo "Bringing up the loopback interface..." ifconfig lo 127.0.0.1 evaluate_retval echo "Setting hostname to $HOSTNAME..." |