您的位置:首页 > 其它

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删除掉就可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: