AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 14858
Accepted
itsadok
itsadok
Asked: 2010-11-26 01:26:25 +0800 CST2010-11-26 01:26:25 +0800 CST 2010-11-26 01:26:25 +0800 CST

如何定义默认关闭的辅助 IP 地址

  • 772

我可以通过添加行在同一网卡上定义辅助 IP 地址

auto eth0:1
iface eth0:1 inet static
        address 192.168.9.101
        ...

到/etc/network/interfaces.

ifup这给了我一个 IP 地址,我可以使用和打开或关闭它ifdown。但是,默认情况下它是打开的。通过阅读手册页,似乎默认情况下将其关闭,我只需要删除该行auto eth0:1。但是,这使得 ifup/down 根本不起作用。

有没有办法做到这一点?

更新:好的,所以问题比我想象的要简单得多。这是我最初做的:

root@dev003:~# 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

# The primary network interface
auto eth0
iface eth0 inet static
    address 192.168.2.101
    netmask 255.255.0.0
    network 192.168.0.0
    broadcast 192.168.255.255
    gateway 192.168.1.1
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers 192.168.1.1

auto eth0:1
iface eth0:1 inet static
    address 192.168.9.101
    netmask 255.255.0.0
    network 192.168.0.0
    broadcast 192.168.255.255
    gateway 192.168.1.1
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers 192.168.1.1

root@dev003:~# /etc/init.d/networking restart
 * Reconfiguring network interfaces...                                                                                                                       ssh stop/waiting
ssh start/running, process 3339
ssh stop/waiting
ssh start/running, process 3373
                                                                                                                                                      [ OK ]
root@dev003:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:03:43:82  
          inet addr:192.168.2.101  Bcast:192.168.255.255  Mask:255.255.0.0
          inet6 addr: fe80::a00:27ff:fe03:4382/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2836310 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2806585 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:220309837 (220.3 MB)  TX bytes:187167315 (187.1 MB)

eth0:1    Link encap:Ethernet  HWaddr 08:00:27:03:43:82  
          inet addr:192.168.9.101  Bcast:192.168.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1909267 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1909267 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:160262241 (160.2 MB)  TX bytes:160262241 (160.2 MB)

root@dev003:~# sed -i 's/auto eth0:1/#auto eth0:1/' /etc/network/interfaces 
root@dev003:~# /etc/init.d/networking restart
 * Reconfiguring network interfaces...                                                                                                                       SIOCDELRT: No such process
ssh stop/waiting
ssh start/running, process 3787
                                                                                                                                                      [ OK ]
root@dev003:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:03:43:82  
          inet addr:192.168.2.101  Bcast:192.168.255.255  Mask:255.255.0.0
          inet6 addr: fe80::a00:27ff:fe03:4382/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2840372 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2810267 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:220637496 (220.6 MB)  TX bytes:187451978 (187.4 MB)

eth0:1    Link encap:Ethernet  HWaddr 08:00:27:03:43:82  
          inet addr:192.168.9.101  Bcast:192.168.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1911328 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1911328 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:160435069 (160.4 MB)  TX bytes:160435069 (160.4 MB)

root@dev003:~# ifdown eth0:1
ifdown: interface eth0:1 not configured

这就是我被卡住的地方,并认为在这样的配置中使用 ifup/down 有问题。事实证明,解决方案非常简单:

root@dev003:~# ifup eth0:1
ssh stop/waiting
ssh start/running, process 3829
root@dev003:~# ifdown eth0:1
root@dev003:~# ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:03:43:82  
          inet addr:192.168.2.101  Bcast:192.168.255.255  Mask:255.255.0.0
          inet6 addr: fe80::a00:27ff:fe03:4382/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:2840609 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2810473 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:220656625 (220.6 MB)  TX bytes:187469288 (187.4 MB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:1911447 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1911447 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:160445053 (160.4 MB)  TX bytes:160445053 (160.4 MB)

感谢@Gilles 给我打电话,并感谢@Marius 提供替代解决方案。

networking ifconfig
  • 1 1 个回答
  • 24563 Views

1 个回答

  • Voted
  1. Best Answer
    Marius Gedminas
    2010-11-26T12:10:10+08:002010-11-26T12:10:10+08:00

    我不知道您是否可以使用ifup/来实现这一点ifdown,但是您可以在运行时从接口中添加或删除 IP 地址

    ip addr add 192.168.9.101/32 dev eth0
    

    和

    ip addr del 192.168.9.101/32 dev eth0
    

    反而。

    你不需要为此定义任何虚拟的“eth0:1”接口(虽然你可以,如果你想,通过label eth0:1在前面添加dev eth0,我想。我从来没有看到这一点。)。

    最后,如果您在某个时候改变主意并决定默认使用此辅助 IP,您可以在 /etc/network/interfaces 中执行此操作:

    auto eth0
    iface eth0 inet ...
        ... whatever you have there already for eth0 ...
        up ip addr add 192.168.9.101/32 dev eth0 
    
    • 8

相关问题

  • 如何设置 VLAN 转发?

  • 如何将主机 Ubuntu 上的 VPN (tun0) 网络适配器映射到 VirtualBox 来宾 Windows?

  • 如何限制下载/上传带宽?

  • 如何通过 Windows 网络共享文件?

  • 面板小程序以文本形式显示当前网络流量?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何安装 .run 文件?

    • 7 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    如何获得 CPU 温度?

    • 21 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Marko Smith

    如何使用命令行将用户添加为新的 sudoer?

    • 7 个回答
  • Marko Smith

    更改文件夹权限和所有权

    • 9 个回答
  • Marko Smith

    你如何重新启动Apache?

    • 13 个回答
  • Marko Smith

    如何卸载软件?

    • 11 个回答
  • Marko Smith

    如何删除 PPA?

    • 26 个回答
  • Martin Hope
    NES 如何启用或禁用服务? 2010-12-30 13:03:32 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    Olivier Lalonde 如何在结束 ssh 会话后保持进程运行? 2010-10-22 04:09:13 +0800 CST
  • Martin Hope
    David B 如何使用命令行将用户添加为新的 sudoer? 2010-10-16 04:02:45 +0800 CST
  • Martin Hope
    Hans 如何删除旧内核版本以清理启动菜单? 2010-08-21 19:37:01 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve