设为首页 收藏本站
查看: 976|回复: 0

[经验分享] Debian6双网卡网关服务器中的网卡设置

[复制链接]

尚未签到

发表于 2018-5-15 10:21:33 | 显示全部楼层 |阅读模式
  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删除掉就可以了。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-460376-1-1.html 上篇帖子: debian squeeze 6.0 安装 virtualbox AMD64架构 下篇帖子: debian 6.4 64位下面使用flash 和触摸板
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表