Zhigang Wang
  • Home
  • Blog
  • Wiki
  • LDP
  • Planet

Linux网络配置基础

Last modified on 2009-12-01

下面是Linux网络配置的一些技巧。

  1. 将多块网卡绑定一个IP,是一种廉价的增加计算机吞吐量的方式,尤其在服务器上特别实用:
     # ifconfig eth0 down
     # ifconfig eth1 down
     # modprobe bonding
     # ifconfig bond0 192.168.0.1
     # ifenslave eth0
     # ifenslave eth1
    
    可以将以上的脚本加入/etc/rc.local中,让其开机自动运行。
  2. 为一块网卡绑定多个IP,即IP别名(alias):
     # ifconfig eth0:0 192.168.0.2
     # ifconfig eth0:1 192.168.0.3
         ......
    
    依次类推,Linux最多可支持255个IP别名。
  3. 将计算机配置成网桥,来连接两个网段: 首先,如果您的系统中没有brctl这个命令的话,请下载bridge-utils,编译,安装。 第一步, 将网络接口的IP归0。Linux下的网桥需要操作网络接口,但是接口上不能运行TCP/IP协议:
     # ifconfig eth0 0.0.0.0
     # ifconfig eth1 0.0.0.0
    
    第二步,创建一个网桥并且增加网络接口:
    # brctl addbr mybridge
    # brctl addif mybridge eth0
    # brctl addif mybridge eth1
    
    第三步,启用网桥:
     # ifconfig mybridge up
    
    这样一个网桥就配置成功了。但是这样配置的网桥本身没有IP地址,管理员就无法远程登陆到该计算机进行配置。一个可选的方案就是给虚拟网络接口mybridge配置一个IP:
     # ifconfig mybridge 192.168.0.1 netmask 255.255.255.0 up
    
  4. 将计算机配置成网关:
     # echo 1 > /proc/sys/net/ipv4/ip_forward  # 打开
     # echo 0 > /proc/sys/net/ipv4/ip_forward  # 关闭
    
  5. 让linux系统对ping不反应,实现起来很方便:
     # echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all  # 打开
     # echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all  # 关闭
    
  6. 查询系统监听的端口信息:
     # netstat -ln
    
  7. 查询端口对应服务:
     # lsof -i
    
  8. 修改网卡的物理地址(MAC):
     # ifconfig eth0 down
     # ifconfig eth0 hw ether 12:34:56:78:90:ab
     # ifconfig eth0 up
    
  9. 将网卡设置成混杂(promiscuous)模式:
     # ifconfig eth0 promisc
    
 

Categories

  • All contents
  • English contents
  • Chinese contents

Feeds

  • AtomAll contents
  • AtomEnglish contents
  • AtomChinese contents

Tags

  • gtd
  • syslog
  • twiki
  • virtualizaion
  • wiki
  • xen

Copyright © 2012 Zhigang Wang. Some right reserved.

The views expressed on this web site are my own and do not necessarily reflect the views of Oracle.