Debian6双网卡网关服务器中的网卡设置
2012-03-14 18:53
344 查看
gateway1:~# cat /etc/network/interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
#eth0: 00:89:59:18:37:0b
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168..2
netmask 255.255.0.0
network 192.168.0.0
broadcast 192.168.255.255
#gateway 192.168.0.1
#dns-nameservers 192.168.0.254
#eth1: 00:44:87:4d:40:e6
auto eth1
allow-hotplug eth1
iface eth1 inet static
address 192.168.2.3
netmask 255.255.255.0
network 192.168.2.0
gateway 192.168.2.1
broadcast 192.168.2.255
gateway1:~# cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 192.168.0.254
gw2:~#
========================
在linux中设定IP时我常常会设为auto eth0
这样的意思是「一开机就自动启动eth0设备,不管有沒有插上网线」
如果开机没有插上网线,系统也会让dhclient3去设定,这样只有等超时才能继续开机。
如果设为allow-hotplug eth0就不会出现上面,先不插网线,开开机插上网线也可以。但是
在debian linux 里用/etc/init.d/networking restart后会出现网卡没有起来,非要用ifup eth0
才行。所以为了方便起见还是用auto eth0比较好。
===========
我的系统中装了dhclient,由它向路由器里面的dhcp服务器发出请求,要求分配IP,Debian的网络配置文件是/etc/network /interfaces,它决定哪个网络设备来用这个IP,如果dhcp服务器发出了回应,却找不到配置文件中的网络设备所对应的物理设备,那么自动分配 宣告失败。问题有时候会出现在独立网卡上面,在PCI上的插槽位置的变化会使网卡的设备号发生变化,用ifconfig加上-a的参数可以知道网卡设备号 是什么,比如,原来网卡的设备号是eth0,这个0指第一块网卡,但把网卡换了插槽,下一次系统启动后会识别到现在的网卡的位置与原来所记录的不同,它会 自动把现在的网卡认为是第二块网卡,所以把它认作eth1,如果再换另一个插槽,它又变回eth0,如果我们换一块带集成网卡的另一个主板,同样的系统会 把这个网卡识别为eth2,所以,如果想要避免硬件变动带来的配置上的不便,可以在/etc/network/interfaces 中把网卡可能出现的设备号eth0、eth1、eth2全写进去:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo eth0 eth1 eth2
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp
allow-hotplug eth1
iface eth1 inet dhcp
allow-hotplug eth2
iface eth2 inet dhcp
===========
cat /etc/network/interfaces 文件,看是否有auto eth0;有表示开机自动启动网卡;没有可以使用vi编辑文件,另起一行添加auto eth0
====================
第一种:在Debian中网卡的设置可以通过/etc/network /interfaces文件来进行,具体可分为三种不同的配置方式:DHCP自动获取、静态分配IP地址和PPPoE宽带拨号。具体设置如下: 在进行配置之前,首先进入/etc/network目录中,编辑interfaces文件:
网卡通过DHCP自动获取IP地址
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
#
# The loopback network interface(配置环回口)
# 开机自动激lo接口
auto lo
# 配置lo接口为环回口
iface lo inet loopback
#
# The primary network interface (配置主网络接口)
#开机自动激活eth0接口
auto eth0
#配置eth0接口为DHCP自动获取
iface eth0 inet dhcp
网卡静态分配IP地址
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
#
# The loopback network interface(配置环回口)
# 开机自动激lo接口
auto lo
# 配置lo接口为环回口
iface lo inet loopback
#
# The primary network interface (配置主网络接口)
#开机自动激活eth0接口
auto eth0
#配置eth0接口为静态设置IP地址
iface eth0 inet static
address 10.16.3.99
netmask 255.255.255.0
network 10.16.3.0
broadcast 10.16.3.255
gateway 10.16.3.1
# dns-* options are implemented by the resolvconf package, if installed(DNS设置)
#请按照时间情况添写DNS ip地址
dns-nameservers x.x.x.x x.x.x.x
dns-search fireteam.org
网卡进行PPPoE宽带拨号配置
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
#
# The loopback network interface(配置环回口)
# 开机自动激lo接口
auto lo
# 配置lo接口为环回口
iface lo inet loopback
#
# The primary network interface (配置主网络接口)
#开机自动激活eth0接口
auto eth0
#配置eth0接口为静态设置IP地址
iface eth0 inet static
address 10.16.3.99
netmask 255.255.255.0
network 10.16.3.0
broadcast 10.16.3.255
配置完毕后,重启计算机或网络服务即可将网卡配好。如进行PPPoE宽带拨号,可运行pppoeconf命令进行配置。
第二:
vi /etc/network/interfaces 网卡配置文件
#回环网卡lo
auto lo
iface lo inet loopback
#第一块网卡eth0
auto eth0
#动态DHCP
iface eth0 inet dhcp
#静态IP
iface eth0 inet static
address 172….
netmask 255….
gateway 172…
dns-nameservers 172…(或在/etc/resolv.conf 设置DNS服务器 nameserver 172…)
重启网卡
/etc/init.d/networking restart
ifdown eth0
ifup eth0
Debian在/etc/udev/rules.d/z25_persistent-net.rules绑定MAC地址与eth0这样interface名。
如果更改了网卡物理地址或新换了网卡,需把这里的名字与/etc/network/interfaces里的同步。
如果用了DHCP协议,/etc/dhcp3/dhclient.conf也是一个需要查看的地方。
我自己遇到这样的问题:每次开机后,ifcofig发现ethxx(其中xx代表数字)中xx会加1,比如这次是etch0,下次开机就是eth1,以此类推eth2...eth21...,解决的办法如下:
***************************
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp
***************************
以上为原来的设置,改动后的设置如下:
***************************
auto lo
iface lo inet loopback
#allow-hotplug eth0
auto eth0
iface eth0 inet dhcp
***************************
然后把/etc/udev/rules.d/目录下的这个文件z25_persistent-net.rules删除掉就可以了。
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
#eth0: 00:89:59:18:37:0b
auto eth0
allow-hotplug eth0
iface eth0 inet static
address 192.168..2
netmask 255.255.0.0
network 192.168.0.0
broadcast 192.168.255.255
#gateway 192.168.0.1
#dns-nameservers 192.168.0.254
#eth1: 00:44:87:4d:40:e6
auto eth1
allow-hotplug eth1
iface eth1 inet static
address 192.168.2.3
netmask 255.255.255.0
network 192.168.2.0
gateway 192.168.2.1
broadcast 192.168.2.255
gateway1:~# cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 192.168.0.254
gw2:~#
========================
在linux中设定IP时我常常会设为auto eth0
这样的意思是「一开机就自动启动eth0设备,不管有沒有插上网线」
如果开机没有插上网线,系统也会让dhclient3去设定,这样只有等超时才能继续开机。
如果设为allow-hotplug eth0就不会出现上面,先不插网线,开开机插上网线也可以。但是
在debian linux 里用/etc/init.d/networking restart后会出现网卡没有起来,非要用ifup eth0
才行。所以为了方便起见还是用auto eth0比较好。
===========
我的系统中装了dhclient,由它向路由器里面的dhcp服务器发出请求,要求分配IP,Debian的网络配置文件是/etc/network /interfaces,它决定哪个网络设备来用这个IP,如果dhcp服务器发出了回应,却找不到配置文件中的网络设备所对应的物理设备,那么自动分配 宣告失败。问题有时候会出现在独立网卡上面,在PCI上的插槽位置的变化会使网卡的设备号发生变化,用ifconfig加上-a的参数可以知道网卡设备号 是什么,比如,原来网卡的设备号是eth0,这个0指第一块网卡,但把网卡换了插槽,下一次系统启动后会识别到现在的网卡的位置与原来所记录的不同,它会 自动把现在的网卡认为是第二块网卡,所以把它认作eth1,如果再换另一个插槽,它又变回eth0,如果我们换一块带集成网卡的另一个主板,同样的系统会 把这个网卡识别为eth2,所以,如果想要避免硬件变动带来的配置上的不便,可以在/etc/network/interfaces 中把网卡可能出现的设备号eth0、eth1、eth2全写进去:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo eth0 eth1 eth2
iface lo inet loopback
# The primary network interface
allow-hotplug eth0
iface eth0 inet dhcp
allow-hotplug eth1
iface eth1 inet dhcp
allow-hotplug eth2
iface eth2 inet dhcp
===========
cat /etc/network/interfaces 文件,看是否有auto eth0;有表示开机自动启动网卡;没有可以使用vi编辑文件,另起一行添加auto eth0
====================
第一种:在Debian中网卡的设置可以通过/etc/network /interfaces文件来进行,具体可分为三种不同的配置方式:DHCP自动获取、静态分配IP地址和PPPoE宽带拨号。具体设置如下: 在进行配置之前,首先进入/etc/network目录中,编辑interfaces文件:
网卡通过DHCP自动获取IP地址
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
#
# The loopback network interface(配置环回口)
# 开机自动激lo接口
auto lo
# 配置lo接口为环回口
iface lo inet loopback
#
# The primary network interface (配置主网络接口)
#开机自动激活eth0接口
auto eth0
#配置eth0接口为DHCP自动获取
iface eth0 inet dhcp
网卡静态分配IP地址
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
#
# The loopback network interface(配置环回口)
# 开机自动激lo接口
auto lo
# 配置lo接口为环回口
iface lo inet loopback
#
# The primary network interface (配置主网络接口)
#开机自动激活eth0接口
auto eth0
#配置eth0接口为静态设置IP地址
iface eth0 inet static
address 10.16.3.99
netmask 255.255.255.0
network 10.16.3.0
broadcast 10.16.3.255
gateway 10.16.3.1
# dns-* options are implemented by the resolvconf package, if installed(DNS设置)
#请按照时间情况添写DNS ip地址
dns-nameservers x.x.x.x x.x.x.x
dns-search fireteam.org
网卡进行PPPoE宽带拨号配置
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
#
# The loopback network interface(配置环回口)
# 开机自动激lo接口
auto lo
# 配置lo接口为环回口
iface lo inet loopback
#
# The primary network interface (配置主网络接口)
#开机自动激活eth0接口
auto eth0
#配置eth0接口为静态设置IP地址
iface eth0 inet static
address 10.16.3.99
netmask 255.255.255.0
network 10.16.3.0
broadcast 10.16.3.255
配置完毕后,重启计算机或网络服务即可将网卡配好。如进行PPPoE宽带拨号,可运行pppoeconf命令进行配置。
第二:
vi /etc/network/interfaces 网卡配置文件
#回环网卡lo
auto lo
iface lo inet loopback
#第一块网卡eth0
auto eth0
#动态DHCP
iface eth0 inet dhcp
#静态IP
iface eth0 inet static
address 172….
netmask 255….
gateway 172…
dns-nameservers 172…(或在/etc/resolv.conf 设置DNS服务器 nameserver 172…)
重启网卡
/etc/init.d/networking restart
ifdown eth0
ifup eth0
Debian在/etc/udev/rules.d/z25_persistent-net.rules绑定MAC地址与eth0这样interface名。
如果更改了网卡物理地址或新换了网卡,需把这里的名字与/etc/network/interfaces里的同步。
如果用了DHCP协议,/etc/dhcp3/dhclient.conf也是一个需要查看的地方。
我自己遇到这样的问题:每次开机后,ifcofig发现ethxx(其中xx代表数字)中xx会加1,比如这次是etch0,下次开机就是eth1,以此类推eth2...eth21...,解决的办法如下:
***************************
auto lo
iface lo inet loopback
allow-hotplug eth0
iface eth0 inet dhcp
***************************
以上为原来的设置,改动后的设置如下:
***************************
auto lo
iface lo inet loopback
#allow-hotplug eth0
auto eth0
iface eth0 inet dhcp
***************************
然后把/etc/udev/rules.d/目录下的这个文件z25_persistent-net.rules删除掉就可以了。
相关文章推荐
- 记录---debian6 安装网关服务器双网卡
- Debian设置IP地址、网关、DNS
- 一个网卡设置多个ip,添加网关;一个虚拟机添加多个网卡
- FreeBSD 设置网卡IP,网关和DNS
- debian 网卡设置范例 lenny 5.0
- 用双网卡做代理服务器设置具体步骤!(服务器上有网站)
- 双网卡服务器路由设置
- web服务器 双网卡 路由 设置
- 双网卡设置默认网关 2011.11.23
- 一台服务器双网卡设置
- 在Debian中网卡的设置
- 双网卡做网关服务器
- 当两个网卡都需要设置网关时——添加路由
- centos 设置双网卡,双网关
- Linux CentOS修改网卡IP/网关设置
- Debian设置IP地址、网关、DNS
- 服务器设置多网卡绑定!!!
- 在Debian中网卡的设置
- WIN服务器双网卡不同网段互访设置
- FreeBSD 设置网卡IP,网关和DNS