Linux 网络接口配置

初始化网口Ethernet Interface

大部分的网络接口配置都可以在/etc/network/interfaces中解决。例如为网卡配置静态IP(dhcp),设置路由信息,配置IP掩码,设置默认路由等。

PS: 如果想要在系统启动时就自动启动网口,需要添加auto一行,详见下面示例。

使用DHCP自动配置接口

下面3行都是自动配置eth0的例子:

auto eth0
allow-hotplug eth0
iface eth0 inet dhcp
  • 1
  • 2
  • 3
  • 4

如果是DHCPv6的话,使用iface来调整:

iface eth0 inet6 dhcp
  • 1
  • 2

另外, IPv6可以通过无状态地址(stateless address)或是 SLAAC来自动配置。

iface eth0 inet6 auto
  • 1
  • 2

手动配置网口

如果打算手动配置网口的话,需要将最后的状态设置为static,并添加相关的网关信息。

    auto eth0
    iface eth0 inet static
        address 192.0.2.7
        netmask 255.255.255.0
        gateway 192.0.2.254
  • 1
  • 2
  • 3
  • 4
  • 5

IPv6的配置类似:

    iface eth0 inet6 static
        address 2001:db8::c0ca:1eaf
        netmask 64
        gateway 2001:db8::1ead:ed:beef
  • 1
  • 2
  • 3
  • 4

启动网口但不配置IP地址

如果想要创建一个没有IP地址的网口,就需要使用manual方法和pre-up,post-down命令来启动和关闭网口。

   iface eth0 inet manual
      pre-up ifconfig $IFACE up
      post-down ifconfig $IFACE down
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值