ifup:激活网络接口

一、语法

onlylove@ubuntu:~$ ifup -help
Usage: ifup <options> <ifaces...>

Options:
	-h, --help             this help
	-V, --version          copyright and version information
	-a, --all              process all interfaces marked "auto"
	--allow CLASS          ignore non-"allow-CLASS" interfaces
	-i, --interfaces FILE  use FILE for interface definitions
	--state-dir DIR        use DIR to store state information
	-X, --exclude PATTERN  exclude interfaces from the list of
	                       interfaces to operate on by a PATTERN
	-n, --no-act           print out what would happen, but don't do it
	                       (note that this option doesn't disable mappings)
	-v, --verbose          print out what would happen before doing it
	-o OPTION=VALUE        set OPTION to VALUE as though it were in
	                       /etc/network/interfaces
	--no-mappings          don't run any mappings
	--no-scripts           don't run any hook scripts
	--no-loopback          don't act specially on the loopback device
	--force                force de/configuration
	--ignore-errors        ignore errors
onlylove@ubuntu:~$

二、参数说明

参数说明
-h, --help帮助
-V, --version版权和版本信息
-a, --all处理所有标记为"auto"的接口
–allow CLASS忽略非"allow-CLASS"接口
-i, --interfaces FILE使用 FILE 进行接口定义
–state-dir DIR使用 DIR 存储状态信息
-X, --exclude PATTERN从 PATTERN 要操作的接口列表中排除接口
-n, --no-act打印出将发生的情况,但不要这样做(请注意,此选项不会禁用映射)
-v, --verbose在执行之前打印出会发生什么
-o OPTION=VALUE将 OPTION 设置为 VALUE,就好像它位于 /etc/network/interfaces 中一样
–no-mappings不运行任何映射
–no-scripts不运行任何挂钩脚本
–no-loopback不要在环回设备上特别操作
–force强度/配置
–ignore-errors忽略错误

三、特别说明

ifup 其实是 script 程序,它会直接到 /etc/ sysconfig/network-scripts 目录下搜索对应的配置文件,例如 ifup eth0,它会找出 ifcfg-eth0 这个文件的内容,然后加以设置。

四、配置 ifcfg-eth0

网络接口配置文件 ifcfg-eth0 在 /etc/sysconfig/network-script 在这个目录下面,存放的是网络接口(网卡)的脚本文件(控制文件),ifcfg-eth0 是默认的第一个网络接口,如果机器中有多网络接口,那么名字就将依此类推 ifcfg-eth1、ifcfg-eth2、ifcfg-eth3 ……

配置项说明
DEVICE接口名(设备,网卡)
USERCTL[yes|no](非root用户是否可以控制该设备)
BOOTPROTOIP 的配置方法 [none|static|bootp|dhcp](引导时不使用协议|静态分配IP|BOOTP协议|DHCP协议)
HWADDRMAC地址
ONBOOT系统启动的时候网络接口是否有效(yes/no)
TYPE网络类型(通常是Ethemet)
NETMASK网络掩码
IPADDRIP地址
IPV6INITIPV6是否有效(yes/no)
GATEWAY默认网关IP地址
BROADCAST默认网关IP地址
NETWORK网络地址

示例:

DEVICE=eth0        
BOOTPROTO=static        
BROADCAST=192.168.1.255        
HWADDR=00:0C:2x:6x:0x:xx        
IPADDR=192.168.1.23        
NETMASK=255.255.255.0        
NETWORK=192.168.1.0        
ONBOOT=yes        
TYPE=Ethernet

五、man ifup

ifup(8)                                                                                                          ifup(8)

NAME
       ifup - bring a network interface up 启动一个网络接口

       ifdown - take a network interface down 关闭一个网络接口

       ifquery - parse interface configuration 解析接口配置

SYNOPSIS
       ifup [-nv] [--no-act] [--verbose] [-i FILE|--interfaces=FILE] [--state-dir=DIR] [--allow CLASS] -a|IFACE...
       ifup -h|--help
       ifup -V|--version

       ifdown [-nv] [--no-act] [--verbose] [-i FILE|--interfaces=FILE] [--state-dir=DIR] [--allow CLASS] -a|IFACE...

       ifquery [-nv] [--verbose] [-i FILE|--interfaces=FILE] [--state-dir=DIR] [--allow CLASS] IFACE...

       ifquery -l|--list [-nv] [--verbose] [-i FILE|--interfaces=FILE] [--state-dir=DIR] [--allow CLASS] [-a|IFACE...]

       ifquery --state [--state-dir=DIR] [--allow CLASS] [-a|IFACE...]

DESCRIPTION
       The ifup and ifdown commands may be used to configure (or, respectively, deconfigure) network interfaces based on interface definitions in the file /etc/network/interfaces.  ifquery command may be used to parse interfaces  configuration.

       ifup 和 ifdown 命令可用于根据文件 /etc/network/interfaces 中的接口定义配置(或分别取消配置)网络接口。ifquery 命令可用于解析接口配置。

OPTIONS
       A summary of options is included below. 选项摘要如下。

       -a, --all
              If given to ifup, affect all interfaces marked auto.  Interfaces are brought up in the order in which they are defined in /etc/network/interfaces.  Combined with --allow, acts on  all  interfaces  of  a  specified class instead.  If given to ifdown, affect all defined interfaces.  Interfaces are brought down in the order in which they are currently listed in the state file. Only interfaces defined  in  /etc/network/interfaces will be brought down.

              如果设置为 ifup,则影响标记为自动的所有接口。接口按照它们在 /etc/network/interfaces 中定义的顺序进行。与 --allow 结合使用时,将改为作用于指定类的所有接口。如果设置为 ifdown,则影响所有定义的接口。接口将按其当前在状态文件中列出的顺序关闭。只有 /etc/network/interfaces 中定义的接口才会被关闭。

       --force
              Force configuration or deconfiguration of the interface.

              强制配置或取消配置接口。

       --ignore-errors
              If any of the commands of scripts fails, continue.

              如果脚本中的任何命令失败,请继续执行。

       -h, --help
              Show summary of options.

              显示选项摘要。

       --allow=CLASS
              Only allow interfaces listed in an allow-CLASS line in /etc/network/interfaces to be acted upon.

              仅允许对 /etc/network/interfaces 中的 allow-CLASS 行中列出的接口执行操作。

       -i FILE, --interfaces=FILE
              Read interface definitions from FILE instead of from /etc/network/interfaces.

              从 FILE 而不是从 /etc/network/interfaces 读取接口定义。

       --state-dir=DIR
              Keep interface state in DIR instead of in /run/network.

              将接口状态保留在 DIR 中,而不是在 /run/network 中。

       -X PATTERN, --exclude=PATTERN
              Exclude  interfaces  from the list of interfaces to operate on by the PATTERN.  PATTERN uses a usual shell glob syntax. If shell wildcards are not used, it must match the exact interface name. This option  may  be specified multiple times resulting in more than one pattern being excluded.

              从 PATTERN 要操作的接口列表中排除接口。PATTERN 使用通常的 shell glob 语法。如果未使用 shell 通配符,则它必须与确切的接口名称匹配。此选项可能被指定多次,导致多个模式被排除。

       -o OPTION=VALUE
              Set OPTION to VALUE as though it were in /etc/network/interfaces.

              将 OPTION 设置为 VALUE,就好像它位于 /etc/network/interfaces 中一样。

       -n, --no-act
              Don't configure any interfaces or run any "up" or "down" commands.

              不要配置任何接口或运行任何"up"或"down"命令。

       --no-mappings
              Don't run any mappings.  See interfaces(5) for more information about the mapping feature.

              不要运行任何映射。 有关映射功能的更多信息,请参见接口(5)。

       --no-scripts
              Don't run any scripts under /etc/network/if-*.d/

              不要在 /etc/network/if-*.d/ 下运行任何脚本

       --no-loopback
              Disable  special  handling  of the loopback interface. By default, the loopback interface (lo on Linux) is predefined internally as an auto interface, so it's brought up on ifup -a automatically. In the  case  the loopback  device  is redefined by user, the interface is configured just once anyway. If, however, another interface is also defined as loopback, it's configured as usual. Specifying this option disables this  behaviour, so the loopback interface won't be configured automatically.

              禁用环回接口的特殊处理。默认情况下,环回接口(在 Linux 上为 lo)在内部预定义为自动接口,因此它会自动在 ifup -a 上启动。如果环回设备由用户重新定义,则接口只配置一次。但是,如果另一个接口也定义为环回,则将照常配置它。指定此选项将禁用此行为,因此不会自动配置环回接口。

       -V, --version
              Show copyright and version information.

              显示版权和版本信息。

       -v, --verbose
              Show commands as they are executed.

              当命令执行时显示它们。

       -l, --list
              For  ifquery,  list all the interfaces which match the specified class.  If no class specified, prints all the interfaces listed as auto.

              对于 ifquery,请列出与指定类匹配的所有接口。如果未指定类,则打印列为自动的所有接口。

       --state
              For ifquery, dump the state of the interfaces. When no interfaces specified, lists all interfaces  brought up  together  with logical interfaces assigned to them and exits with a status code indicating success. If one or more interfaces specified, display state of these interfaces only; successful code is  returned  if all of interfaces given as arguments are up. Otherwise, 0 is returned.

              对于 ifquery,请转储接口的状态。如果未指定接口,则列出所有接口,并分配有分配给它们的逻辑接口,并退出并显示指示成功的状态代码。如果指定了一个或多个接口,则仅显示这些接口的状态;如果作为参数给出的所有接口都已启动,则返回成功的代码。否则,将返回 0。

EXAMPLES
       ifup -a
              Bring up all the interfaces defined with auto in /etc/network/interfaces

              在/etc/network/interfaces中调出所有用auto定义的接口

       ifup eth0
              Bring up interface eth0

              调出接口 eth0

       ifup eth0=home
              Bring up interface eth0 as logical interface home

              将接口 eth0 作为逻辑接口主页

       ifdown -a
              Bring down all interfaces that are currently up.

              关闭当前处于打开状态的所有接口。

       ifquery -l
              Print names of all interfaces specified with the auto keyword.

              打印使用 auto 关键字指定的所有接口的名称。

       ifquery -l --allow=hotplug
              Print names of all interfaces specified with the allow-hotplug keyword.

              打印使用 allow-hotplug 关键字指定的所有接口的名称。

       ifquery eth0
              Display  the  interface options as specified in the ifupdown configuration. Each key-value pair is printed out on individual line using ": " as separator.

              显示 ifupdown 配置中指定的接口选项。每个键值对都使用":"作为分隔符打印在单独的行上。

NOTES
       ifup, ifdown, and ifquery are actually the same program called by different names.

       The program does not configure network interfaces directly; it runs low level utilities such  as  ip  to  do  its dirty work.

       When invoked, ifdown checks if ifup is still running. In that case, SIGTERM is sent to ifup.

       During interface deconfiguration, ifdown ignores errors the same way as if --ignore-errors was specified.

       ifup、ifdown 和 ifquery 实际上是由不同名称调用的同一程序。

       该程序不直接配置网络接口;它运行低级实用程序(如ip)来完成其肮脏的工作。

       调用时,ifdown 会检查 ifup 是否仍在运行。在这种情况下,SIGTERM 将发送到 ifup。

       在接口取消配置期间,ifdown 忽略错误的方式与指定 --ignore-errors 的方式相同。

FILES
       /etc/network/interfaces
              definitions of network interfaces See interfaces(5) for more information.

              网络接口的定义请参见接口(5)。

       /run/network/ifstate
              current state of network interfaces

              网络接口的当前状态

CONCURRENCY
       Ifupdown uses per-interface locking to ensure that concurrent ifup and ifdown calls to the same interface are run in serial.  However, calls to different interfaces will be able to run in parallel.

       Ifupdown 使用每个接口锁定来确保对同一接口的并发 ifup 和 ifdown 调用以串行方式运行。 但是,对不同接口的调用将能够并行运行。

EXIT STATUS
       For ifup and ifdown, the exit status will be 0 if the given interface(s) have all  been  (de)configured  successfully,  1  if there was any error.  The result of these commands is idempotent; running ifup on an interface that is already up will result in an exit status of 0, and similarly running ifdown on an interface  that  is  not  up will also result in an exit status of 0.

       ifquery  will  normally  return with exit status 0 if an interface with a matching iface stanza, 1 if there is no matching stanza.  ifquery --state will also return with exit status 1 if the given interface was  known  but  was not up.

       对于 ifup 和 ifdown,如果给定接口全部已成功配置(取消)配置,则退出状态将为 0;如果出现任何错误,则退出状态为 1。这些命令的结果是幂等的;在已启动的接口上运行 ifup 将导致退出状态为 0,同样,在未启动的接口上运行 ifdown 也将导致退出状态为 0。

       如果接口具有匹配的 iface 节,ifquery 通常会返回退出状态 0;如果没有匹配的节,则返回 1。如果给定接口已知但未启动,则 ifquery --state 也将返回退出状态 1。

KNOWN BUGS/LIMITATIONS
       The  program  keeps  records of whether network interfaces are up or down.  Under exceptional circumstances these records can become inconsistent with the real states of the interfaces.   For  example,  an  interface  that  was brought  up  using  ifup and later deconfigured using ifconfig will still be recorded as up.  To fix this you can use the --force option to force ifup or ifdown to run configuration or deconfiguration commands despite  what  it considers the current state of the interface to be.

       The  file  /run/network/ifstate  must  be  writable for ifup or ifdown to work properly.  If that location is not writable (for example, because the root filesystem is mounted  read-only  for  system  recovery)  then  /run/network/ifstate should be made a symbolic link to a writable location.  If that is not possible then you can use the --force option to run configuration or deconfiguration commands without updating the file.

       Note that the program does not run automatically: ifup alone does not bring up interfaces that appear as a result of  hardware  being installed and ifdown alone does not bring down interfaces that disappear as a result of hardware being removed.  To automate the configuration of network interfaces you need to install other packages  such as udev(7) or ifplugd(8).

       该程序保留网络接口是打开还是关闭的记录。在特殊情况下,这些记录可能与接口的实际状态不一致。例如,使用ifup启动的接口,后来使用ifconfig解除配置,仍然会被记录为up。要解决此问题,您可以使用 --force 选项强制 ifup 或 ifdown 运行配置或取消配置命令,尽管它认为接口的当前状态是什么。

       文件 /run/network/ifstate 必须可写,ifup 或 ifdown 才能正常工作。如果该位置不可写(例如,因为根文件系统是为系统恢复而以只读方式挂载的),则应将 /run/network/ifstate 设置为指向可写位置的符号链接。如果无法做到这一点,则可以使用 --force 选项运行配置或取消配置命令,而无需更新文件。

       请注意,该程序不会自动运行:ifup 本身不会显示由于安装了硬件而出现的接口,并且 ifdown 本身不会关闭因删除硬件而消失的接口。要自动配置网络接口,您需要安装其他软件包,如 udev(7) 或 ifplugd(8)。

AUTHORS
       The  ifupdown  suite  was  created by Anthony Towns <aj@azure.humbug.org.au>, and is currently maintained by Guus
       Sliepen <guus@debian.org>.

       Many others have helped develop ifupdown over time, see /usr/share/doc/ifupdown/changelog.Debian.gz  for  a  full
       history.

SEE ALSO
       interfaces(5), ip(8), ifconfig(8).

IFUPDOWN                                               11 Jan 2017                                               ifup(8)

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值