Linux ifconfig 可以用来配置网络接口的IP地址、掩码、网关、物理地址等;值得一说的是用Linux ifconfig 为网卡指定IP地址,这只是用来调试网络用的,并不会更改系统关于网卡的配置文件。

如果您想把网络接口的IP地址固定下来,目前有三个方法:一是通过各个发行和版本专用的工具来修改IP地址;二是直接修改网络接口的配置文件;三是修改特定的文件,加入Linux ifconfig 指令来指定网卡的IP地址,比如在redhat或Fedora中,把Linux ifconfig 的语名写入/etc/rc.d/rc.local文件中;

Linux ifconfig 配置网络端口的方法: Linux ifconfig 工具配置网络接口的方法是通过指令的参数来达到目的的,我们只说最常用的参数; Linux ifconfig  网络端口  IP地址    hw <HW>  MAC地址  netmask  掩码地址    broadcast  广播地址   [up/down]

实例一:

比如我们用Linux ifconfig 来调试 eth0网卡的地址

  1. [root@localhost ~]# Linux ifconfig  eth0 down
  2. [root@localhost ~]# Linux ifconfig  eth0  192.168.1.99 broadcast 192.168.1.255  netmask 255.255.255.0
  3. [root@localhost ~]# Linux ifconfig eth0 up
  4. [root@localhost ~]# Linux ifconfig eth0
  5. eth0      Link encap:Ethernet  HWaddr 00:11:00:00:11:11
  6. inet addr:192.168.1.99  Bcast:192.168.1.255  Mask:255.255.255.0
  7. UP BROADCAST MULTICAST  MTU:1500  Metric:1
  8. RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  9. TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

10. collisions:0 txqueuelen:1000

11. RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

12. Interrupt:11 Base address:0x3400

注解: 上面的例子我们解说一下;

第一行:Linux ifconfig eth0 down 表示如果eth0是激活的,就把它DOWN掉。此命令等同于 ifdown eth0;

第二行:用Linux ifconfig 来配置 eth0的IP地址、广播地址和网络掩码;

第三行:用Linux ifconfig eth0 up 来激活eth0 ; 此命令等同于 ifup eth0

第四行:用 Linux ifconfig eth0 来查看 eth0的状态;

当然您也可以用直接在指令IP地址、网络掩码、广播地址的同时,激活网卡;要加up参数;比如下面的例子; [root@localhost ~]# Linux ifconfig  eth0  192.168.1.99 broadcast 192.168.1.255  netmask 255.255.255.0 up

实例二:在这个例子中,我们要学会设置网络IP地址的同时,学会设置网卡的物理地址(MAC地址);

比如我们设置网卡eth1的IP地址、网络掩码、广播地址,物理地址并且激活它; [root@localhost ~]# Linux ifconfig eth1 192.168.1.252 hw ether  00:11:00:00:11:11   netmask 255.255.255.0 broadcast 192.168.1.255   up或[root@localhost ~]# Linux ifconfig eth1    hw ether  00:11:00:00:11:22[root@localhost ~]# Linux ifconfig eth1 192.168.1.252   netmask 255.255.255.0 broadcast 192.168.1.255   up

其中 hw 后面所接的是网络接口类型, ether表示乙太网, 同时也支持 ax25 、ARCnet、netrom等,详情请查看 man Linux ifconfig ;

3.3 如何用Linux ifconfig 来配置虚拟网络接口;

有时我们为了满足不同的需要还需要配置虚拟网络接口,比如我们用不同的IP地址来架运行多个HTTPD服务器,就要用到虚拟地址;这样就省却了同一个IP地址,如果开设两个的HTTPD服务器时,要指定端口号。

虚拟网络接口指的是为一个网络接口指定多个IP地址,虚拟接口是这样的 eth0:0 、 eth0:1、eth0:2 ... .. eth1N。当然您为eth1 指定多个IP地址,也就是 eth1:0、eth1:1、eth1:2 ... ...以此类推;

其实用Linux ifconfig 为一个网卡配置多个IP地址,就用前面我们所说的Linux ifconfig的用法,这个比较简单;看下面的例子; [root@localhost ~]# Linux ifconfig eth1:0 192.168.1.251 hw ether  00:11:00:00:11:33   netmask 255.255.255.0 broadcast 192.168.1.255   up或[root@localhost ~]# Linux ifconfig eth1    hw ether  00:11:00:00:11:33[root@localhost ~]# Linux ifconfig eth1 192.168.1.251   netmask 255.255.255.0 broadcast 192.168.1.255   up

注意:指定时,要为每个虚拟网卡指定不同的物理地址;

在 Redhat/Fedora 或与Redhat/Fedora类似的系统,您可以把配置网络IP地址、广播地址、掩码地址、物理地址以及激活网络接口同时放在一个句子中,写入/etc/rc.d/rc.local中。比如下面的例子;

Linux ifconfig eth1:0 192.168.1.250 hw ether  00:11:00:00:11:44   netmask 255.255.255.0 broadcast 192.168.1.255   up

Linux ifconfig eth1:1 192.168.1.249 hw ether  00:11:00:00:11:55   netmask 255.255.255.0 broadcast 192.168.1.255   up

解说:上面是为eth1的网络接口,设置了两个虚拟接口;每个接口都有自己的物理地址、IP地址... ...

3.4 如何用Linux ifconfig 来激活和终止网络接口的连接;

激活和终止网络接口的用 Linux ifconfig 命令,后面接网络接口,然后加上 down或up参数,就可以禁止或激活相应的网络接口了。当然也可以用专用工具ifup和ifdown 工具;

  1. [root@localhost ~]# Linux ifconfig eth0 down
  2. [root@localhost ~]# Linux ifconfig eth0 up
  3. [root@localhost ~]# ifup eth0
  4. [root@localhost ~]# ifdown eth0

对于激活其它类型的网络接口也是如此,比如 ppp0,wlan0等;不过只是对指定IP的网卡有效。 注意:对DHCP自动分配的IP,还得由各个发行版自带的网络工具来激活;当然得安装dhcp客户端;这个您我们应该明白;比如Redhat/Fedora [root@localhost ~]#  /etc/init.d/network start Slackware 发行版; [root@localhost ~]# /etc/rc.d/rc.inet1

Linux ifconfig 配置网络接口的更多相关文章

  1. Linux ifconfig 查看网络接口状态

    Linux ifconfig 如果不接任何参数,就会输出当前网络接口的情况: [root@localhost ~]# Linux ifconfig eth0      Link encap:Ether ...

  2. ifconfig - 配置网络接口

    总览 ifconfig [接口] ifconfig 接口 [aftype] options | address ... 描述 ifconfig 用于配置常驻内核的网络接口.它用于在引导成功时设定网络接 ...

  3. linux网络配置相关命令、虚拟网络接口eth0:0

    网络接口(interface)是网络硬件设备在操作系统中的表示方法,比如网卡在Linux操作系统中用ethX,是由0开始的正整数,比如eth0.eth1...... ethX.而普通猫和ADSL的接口 ...

  4. Linux网络——配置网络之ifconfig家族命令

    Linux网络——配置网络之ifconfig家族命令 摘要:本文主要学习了ifconfig家族用来配置网络的命令. ifconfig命令 ifconfig命令用来显示或设置网络接口信息,设置只是临时生 ...

  5. linux网络配置命令(一)——ifconfig

    linux网络配置命令(一)——ifconfig ifconfig 查看.配置网卡信息.已过时,推荐使用ip命令 格式:  ifconfig [interface]                   ...

  6. linux网络配置命令

    ifconfig 命令命令功能ifconfig命令被用于配置和显不Linux内核中网络接口的网络参数.命令语法ifconfig (参数)参数说明add〈地址〉:设置网络设备IPv6的P地址;del〈地 ...

  7. linux ifconfig命令使用详解

    Linux下网卡命名规律:eth0,eth1.第一块以太网卡,第二块.lo为环回接口,它的IP地址固定为127.0.0.1,掩码8位.它代表你的机器本身. 1.ifconfig是查看网卡的信息. if ...

  8. Linux如何配置bond

    Q:什么是BOND? A: 将多块网卡虚拟成为一块网卡的技术,通过bond技术让多块网卡看起来是一个单独的以太网接口设备并具有相同的ip地址.   Q:为什么要配置bond? A:  在linux下配 ...

  9. LINUX ifconfig 命令详解

    ifconfig 配置和显示Linux系统网卡的网络参数 补充说明 ifconfig命令 被用于配置和显示Linux内核中网络接口的网络参数.用ifconfig命令配置的网卡信息,在网卡重启后机器重启 ...

随机推荐

  1. Zuul上传文件

    对于1M以内的文件上传,无需任何处理,大文件10M以上需要为上传路径添加/zuul前缀,也可使用zuul.servlet-path自定义前缀 如果Zuul使用了Ribbon做负载均衡,那么对于超大的文 ...

  2. 为什么要使用Vue.$set(target,key,value)

    vue中不能检测到数组和对象的两种变化: 1.数组长度的变化 vm.arr.length = 4 2,数组通过索引值修改内容 vm.arr[1] = 'aa' Vue.$set(target,key, ...

  3. [POI2014]KAR-Cards

    题目链接: 传送门 题目分析: 线段树妙题,感觉思路奇奇怪怪的,虽然对我来说不是"线段树菜题"(\(ldx\)神仙\(blog\)原话)\(QAQ\) 考虑怎么样维护可合并的信息解 ...

  4. C++ 函数模板&类模板详解

    在 C++ 中,模板分为函数模板和类模板两种.函数模板是用于生成函数的,类模板则是用于生成类的. 函数模板&模板函数     类模板&模板类  必须区分概念 函数模板是模板,模板函数时 ...

  5. 如何应用AxureRP做原型设计

    什么是原型呢?这个在之前介绍为什么需要进行原型设计当中有提到,原型是产品的最初形态,确认用户对产品界面和操作功能可用性的需求,高保真的原型接近于产品的最终形态,但仍只是原型.产品原型简单的说就是产品设 ...

  6. 用DataTable填充实体类List

    /// <summary> /// 用DataTable填充实体类List /// </summary> public static List<T> FillLis ...

  7. 20-iframe

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 通过three.js实现简易3D打印模型切片展示

    现在的页面展示要求越来越高,美的展示总能吸引更多的访客.最近在学习3D打印中的切片算法,刚刚入门,发现通过three.js框架可以很好展示出3D切片细节(虽然我做的比较简单). //========= ...

  9. CF629E Famil Door and Roads【树上计数+分类讨论】

    Online Judge:Codeforces629E,Luogu-CF629E Label:树上计数,分类讨论,换根 题目描述 给出一棵n个节点的树.有m个询问,每一个询问包含两个数a.b,我们可以 ...

  10. PHP SSH2 不支持 IdentityFile

    有的情况下 我们会用到 类似命令行 sftp -o IdentityFile=.ssh/identity  username@host方式 登陆, 想用php 操作, 但是 php 现在看是不支持的, ...