Linux学习笔记(二)网络接口配置

来源:互联网 发布:qq邮箱搜索软件 编辑:程序博客网 时间:2024/05/16 18:43
一、安装和配置网路设备
      Linux支持的网卡驱动程序都存放在目录/lib/modules/(linux kernel version)/net下。通过修改模块配置文件来更改网卡或者增加网卡。
  1. 修改/etc/conf.modules文件 alias eth(n) modelname 
    options modelname io=IoAddress irq=ItrptRqstNum
  2. 加载模块 insmod modelname
  3. 查看当前加载的模块的信息 lsmod

注:在较老的Linux版本中,系统没有自动检测所有相关硬件的功能,所以得修改/etc/lilo.config文件。在文件后添加
     append="ether=ItrptRqstNum,IoAddress,eth(n) ... "

二、网络接口参数设置
     可采用以下两种方法:
  1. 使用ifconfig临时设置网络接口参数,系统重启后参数恢复到默认配置。如果要想在启动时就修改配置,可在/etc/sysconfig/network文件中加入脚本,如修改MAC为以下几行命令:
    /sbin/ifconfig eth0 down
    /sbin/ifconfig eth0 hw ether XX:XX:XX:XX:XX:XX
    /sbin/ifconfig eht0 up
  2. 使用netconfig设置默认网络参数,包括客户端的配置、服务器的配置和其他的配置。这些默认的网络配置信息存放在 /etc/sysconfig/networking/profiles/default目录下以下几个文件中:
    (1) ifcfg-eth0——IP Address、Network Mask、Network Address等信息,/etc/sysconfig/networking/devices/ifcfg-eth0 和/etc/sysconfig/network-scripts/ifcfg-eth0是该文件的链接;
    (2) network——Hostname
    (3) resolv.conf——DNS
    (4) hosts——主机名称列表,/etc/hosts是该文件的链接;
三、命令行配置
  1. /usr/sbin/usernetctl ifcfg-eth0 up
    其中ifcfg-eth0在/etc/sysconf/network-scripts/下
  2. /etc/sysconf/network-scripts/ifup eth0
  3. ifconfig eth0 hw ether ${MACADDR}
  4. ifconfig eth0 $IPADDR netmask $NETMASK broadcast $BROADCAST
  5. route add -net $NETWORK netmask $NETMASK dev $DEVICE
  6. route add default gw $GATEWAY $DEVICE
原创粉丝点击