现在的位置: 首页 > 综合 > 正文

linux网络配置

2013年02月26日 ⁄ 综合 ⁄ 共 2183字 ⁄ 字号 评论关闭

from: 修改机器名和Ip
1)修改机器名
编辑 /etc/sysconfig/network

NETWORKING = yes
FORWARD_IPV4 = yes
HOSTNAME = xxxx.com #你的主机名
GATEWAY = 123.123.123.123 #网关
GATEWAYDEV = eth0

2) 修改Ip
编辑 /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE = eth0
IPADDR = xxx.xxx.xxx.xxx #你的IP地址
NETMASK = xxx.xxx.xxx.xxx #你的子网掩码
NETWORK = xxx.xxx.xxx.xxx #你的工作网络
BROADCAST = xxx.xxx.xxx.xxx #你的广播址
ONBOOT = yes

运行/etc/sysconfig/network-scripts/ifdown eth0关闭网卡,然后运行 /etc/sysconfig/network-scripts/ifup eth0 启动网卡。

from: 给网卡加第二个IP地址且重启有效
3) 添加第二个Ip
ifconfig eth0:1 ip netmask 255.255.255.0
这个命令后第二个Ip重起会失效。

如果希望重起有效,还需要
cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0:1
然后编辑 /etc/sysconfig/network-scripts/ifcfg-eth0:1

DEVICE = eth0:1
IPADDR = xxx.xxx.xxx.xxx #你的IP地址
NETMASK = xxx.xxx.xxx.xxx #你的子网掩码
NETWORK = xxx.xxx.xxx.xxx #你的工作网络
BROADCAST = xxx.xxx.xxx.xxx #你的广播址
ONBOOT = yes

重起网卡即可。

如果需要再绑定多一个IP地址,只需要把文件名和文件内的DEVICE中的eth0:x加一即可。LINUX最多可以支持255个IP别名。

from: 多个网卡绑定一个IP地址
4)多个网卡绑定一个IP地址(bonding)
  bonding在内核2.4.x中已经包含,编译时需要把网络设备选项中的 Bonding driver support选中。

执行如下命令:
  ismod bonding
  ifconfig eth0 down
  ifconfig eth1 down
  ifconfig bond0 ipaddress
  ifenslave bond0 eth0
  ifenslave bond0 eth1

最好把这几句写成一个脚本,再由/etc/rc.d/rc.local调用,以便一开机就生效。

bonding对于服务器来是个比较好的选择,在没有千兆网卡时,用两三块100兆网卡作 bonding,可大大提高服务器到交换机之间的带宽。但是需要在交换机上设置连接bonding 网卡的两个口子映射为同一个虚拟接口。

如果没有明显使用ifconfig来配置指定,bonding设备的MAC地址从它的第一个slave中得到。这个MAC地址随即被传递个所有其他的 slave设备,这些其他的slave设备将具有这个MAC,即使第一个Slave设备被去除。只有bonding设备重起或者down了,MAC地址才会改变。
如果希望修改MAC地址,可以使用ifconfig来设置:
# ifconfig bond0 ha ether 00:11:22:33:44:55
可以通过up/down设备,然后修改其slave的顺序来改变bonding设备的MAC地址:
# ifconfig bond0 down; modprobe -r bonding
# ifconfig bond0 .... up
# ifenslave bond0 eth...

为了恢复slave的MAC地址,需要将其从bonding设备中分离出来(`ifenslave -d bond0 eth0'),down掉该设备 (`ifconfig eth0 down'),去除模块(`rmmod 3c59x'),然后重载其以使其从其eeproms中得到其MAC地址。若一个驱动被多个设备所拥有,那么需要将其全部down掉。另外一种方法是察看启动时该卡的MAC地址(dmesg或 tail /var/log/messages),并使用ifconfig来reset它:
# ifconfig eth0 down
# ifconfig eth0 hw ether 00:20:40:60:80:A0

from: Linux下的DNS配置详解
5) 修改DNS
编辑 /etc/resolve.conf

nameserver host.dns.addr
一般可以写三个

domain site.domain
指定搜索的域

from: 服务器端如何设置ssh,指定IP访问
6)指定IP访问ssh

如果是系统自带的openssh:

修改hosts.deny:
ALL:ALL@ALL,PARANOID

修改hosts.allow:
sshd,sshd:IP(唯一IP)

如果用的是ssh:
修改/etc/ssh2/sshd2_config  

 

http://bbs.tsinghua.edu.cn/pc/pccon.php?id=4777&nid=110373&pid=0&tag=0&p=p

抱歉!评论已关闭.