许多windows非常熟悉ipconfig命令行工具,它被用来获取网络接口配置信息并对此进行修改。Linux系统拥有一个类似的工具,也就是ifconfig(interfaces config)。通常需要以root身份登录或使用sudo以便在Linux机器上使用ifconfig工具。依赖于ifconfig命令中使用一些选项属性,ifconfig工具不仅可以被用来简单地获取网络接口配置信息,还可以修改这些配置。

1.命令格式:

ifconfig [网络设备] [参数]

2.命令功能:

ifconfig 命令用来查看和配置网络设备。当网络环境发生改变时可通过此命令对网络进行相应的配置。

3.命令参数:

up 启动指定网络设备/网卡。

down 关闭指定网络设备/网卡。该参数可以有效地阻止通过指定接口的IP信息流,如果想永久地关闭一个接口,我们还需要从核心路由表中将该接口的路由信息全部删除。

arp 设置指定网卡是否支持ARP协议。

-promisc 设置是否支持网卡的promiscuous模式,如果选择此参数,网卡将接收网络中发给它所有的数据包

-allmulti 设置是否支持多播模式,如果选择此参数,网卡将接收网络中所有的多播数据包

-a 显示全部接口信息

-s 显示摘要信息(类似于 netstat -i)

add 给指定网卡配置IPv6地址

del 删除指定网卡的IPv6地址

<硬件地址> 配置网卡最大的传输单元

mtu<字节数> 设置网卡的最大传输单元 (bytes)

netmask<子网掩码> 设置网卡的子网掩码。掩码可以是有前缀0x的32位十六进制数,也可以是用点分开的4个十进制数。如果不打算将网络分成子网,可以不管这一选项;如果要使用子网,那么请记住,网络中每一个系统必须有相同子网掩码。

tunel 建立隧道

dstaddr 设定一个远端地址,建立点对点通信

-broadcast<地址> 为指定网卡设置广播协议

-pointtopoint<地址> 为网卡设置点对点通讯协议

multicast 为网卡设置组播标志

address 为网卡设置IPv4地址

txqueuelen<长度> 为网卡设置传输列队的长度

4.使用实例:

实例1:显示网络设备信息(激活状态的)

命令:

ifconfig

输出:

[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr :::BF::
inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (568.7 MiB) TX bytes: (2.7 MiB) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (2.7 KiB) TX bytes: (2.7 KiB)

说明:

eth0 表示第一块网卡, 其中 HWaddr 表示网卡的物理地址,可以看到目前这个网卡的物理地址(MAC地址)是 00:50:56:BF:26:20

inet addr 用来表示网卡的IP地址,此网卡的 IP地址是 192.168.120.204,广播地址, Bcast:192.168.120.255,掩码地址Mask:255.255.255.0

lo 是表示主机的回坏地址,这个一般是用来测试一个网络程序,但又不想让局域网或外网的用户能够查看,只能在此台主机上运行和查看所用的网络接口。比如把 HTTPD服务器的指定到回坏地址,在浏览器输入 127.0.0.1 就能看到你所架WEB网站了。但只是您能看得到,局域网的其它主机或用户无从知道。

第一行:连接类型:Ethernet(以太网)HWaddr(硬件mac地址)

第二行:网卡的IP地址、子网、掩码

第三行:UP(代表网卡开启状态)RUNNING(代表网卡的网线被接上)MULTICAST(支持组播)MTU:1500(最大传输单元):1500字节

第四、五行:接收、发送数据包情况统计

第七行:接收、发送数据字节数统计信息。

实例2:启动关闭指定网卡

命令:

ifconfig eth0 up

ifconfig eth0 down

输出:

说明:

ifconfig eth0 up 为启动网卡eth0 ;ifconfig eth0 down 为关闭网卡eth0。ssh登陆linux服务器操作要小心,关闭了就不能开启了,除非你有多网卡。

实例3:为网卡配置和删除IPv6地址

命令:

ifconfig eth0 add 33ffe:::::/

ifconfig eth0 del 33ffe:::::/

输出:

说明:

ifconfig eth0 add 33ffe:3240:800:1005::2/64 为网卡eth0配置IPv6地址;

ifconfig eth0 add 33ffe:3240:800:1005::2/64 为网卡eth0删除IPv6地址;

练习的时候,ssh登陆linux服务器操作要小心,关闭了就不能开启了,除非你有多网卡。

实例4:用ifconfig修改MAC地址

命令:

ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE

输出:

[root@localhost ~]# ifconfig eth0 down //关闭网卡
[root@localhost ~]# ifconfig eth0 hw ether :AA:BB:CC:DD:EE //修改MAC地址
[root@localhost ~]# ifconfig eth0 up //启动网卡
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr :AA:BB:CC:DD:EE
inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (568.7 MiB) TX bytes: (2.7 MiB) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (2.7 KiB) TX bytes: (2.7 KiB)
[root@localhost ~]# ifconfig eth0 hw ether :::BF:: //关闭网卡并修改MAC地址
[root@localhost ~]# ifconfig eth0 up //启动网卡
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr :::BF::
inet addr:192.168.120.204 Bcast:192.168.120.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (568.7 MiB) TX bytes: (2.7 MiB) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (2.7 KiB) TX bytes: (2.7 KiB)

说明:

实例5:配置IP地址

命令:

输出:

[root@localhost ~]# ifconfig eth0 192.168.120.56
[root@localhost ~]# ifconfig eth0 192.168.120.56 netmask 255.255.255.0
[root@localhost ~]# ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255

说明:

ifconfig eth0 192.168.120.56 

给eth0网卡配置IP地:192.168.120.56

ifconfig eth0 192.168.120.56 netmask 255.255.255.0

给eth0网卡配置IP地址:192.168.120.56 ,并加上子掩码:255.255.255.0

ifconfig eth0 192.168.120.56 netmask 255.255.255.0 broadcast 192.168.120.255

/给eth0网卡配置IP地址:192.168.120.56,加上子掩码:255.255.255.0,加上个广播地址: 192.168.120.255

实例6:启用和关闭ARP协议

命令:

ifconfig eth0 arp

ifconfig eth0 -arp

输出:

[root@localhost ~]# ifconfig eth0 arp
[root@localhost ~]# ifconfig eth0 -arp

说明:

ifconfig eth0 arp 开启网卡eth0 的arp协议;

ifconfig eth0 -arp 关闭网卡eth0 的arp协议;

实例7:设置最大传输单元

命令:

ifconfig eth0 mtu 1500

输出:

[root@localhost ~]# ifconfig eth0 mtu
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr :::BF::1F
inet addr:192.168.120.203 Bcast:192.168.120.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (569.4 MiB) TX bytes: (2.5 MiB) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (505.9 KiB) TX bytes: (505.9 KiB) [root@localhost ~]# ifconfig eth0 mtu
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr :::BF::1F
inet addr:192.168.120.203 Bcast:192.168.120.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (569.4 MiB) TX bytes: (2.5 MiB) lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU: Metric:
RX packets: errors: dropped: overruns: frame:
TX packets: errors: dropped: overruns: carrier:
collisions: txqueuelen:
RX bytes: (505.9 KiB) TX bytes: (505.9 KiB) [root@localhost ~]#

说明:

设置能通过的最大数据包大小为 1500 bytes

备注:用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在。要想将上述的配置信息永远的存的电脑里,那就要修改网卡的配置文件了。

原文:http://www.cnblogs.com/peida/archive/2013/02/27/2934525.html

每天一个linux命令(01):ifconfig命令的更多相关文章

  1. Linux故障:linux中使用ifconfig命令查看网卡信息时显示为eth1,但是在network-scripts中只有ifcfg-eth0的配置文件,并且里面的NAME="eth0"。

    linux中使用ifconfig命令查看网卡信息时显示为eth1,但是在network-scripts中只有ifcfg-eth0的配置文件,并且里面的NAME="eth0".   ...

  2. ip命令和ifconfig命令(转载)

    Linux的ip命令和ifconfig类似,但前者功能更强大,并旨在取代后者.使用ip命令,只需一个命令,你就能很轻松地执行一些网络管理任务.ifconfig是net-tools中已被废弃使用的一个命 ...

  3. 每天一个linux命令(39)--ifconfig命令

    许多人非常熟悉Windows下的ipconfig 命令行工具,它被用来获取网络接口配置信息并对此进行修改.Linux系统拥有一个类似的工具,也就是ifconfig(interfaces  config ...

  4. 每天一个linux命令:ifconfig命令 临时修改重启后恢复原样

    许多windows非常熟悉ipconfig命令行工具,它被用来获取网络接口配置信息并对此进行修改.Linux系统拥有一个类似的工具,也就是ifconfig(interfaces config).通常需 ...

  5. Linux系统下ifconfig命令使用及结果分析

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

  6. 如何解决Linux 系统下 ifconfig 命令无网络接口 ens33

    今天我在做Redis的哨兵集群模式的时候,以前都是好的,也不知道从什么时候开始就无法连接Redis服务器了,就是运行如下命令,没有效果:redis-server redis.conf,然后在通过命令查 ...

  7. LINUX网络之ifconfig命令与ping

    ifconfig命令 网络配置 ifconfig命令被用于配置和显示Linux内核中网络接口的网络参数.用ifconfig命令配置的网卡信息,在网卡重启后机器重启后,配置就不存在.要想将上述的配置信息 ...

  8. linux常用命令:ifconfig 命令

    许多windows非常熟悉ipconfig命令行工具,它被用来获取网络接口配置信息并对此进行修改.Linux系统拥有一个类似的工具,也就是ifconfig(interfaces config).通常需 ...

  9. linux 下ip命令对比ifconfig命令

    原文:https://linux.cn/article-3144-1.html ------------------------------------------------------------ ...

  10. Linux下利用ifconfig命令查看和操纵网络接口

    为了说明这个问题,首先我们需要解释一下在Linux系统下"网络接口"的含义.通俗来讲,Linux中的所谓网络接口就是指本机的网卡,它相当于计算机的一台负责对网络进行收发数据的外设. ...

随机推荐

  1. windows 装XP系统

    笔记本型号:HPCQ40-506AX 1.在BIOS中更改启动顺序:将USB设为第一启动项2.插入装有PE系统的USB设备3.开机后一直按F124.到达选择系统界面,目前我的HPCQ40用其他系统进去 ...

  2. C# 多线程系列(二)

    传递数据给一个线程 通过函数或lambda表达式包一层进行传递. static void Main(string[] args) { Thread thread = new Thread(() =&g ...

  3. VC常用代码之创建进程

    作者:朱金灿 来源:http://blog.csdn.net/clever101 创建进程是编程开发的常用操作.Windows中的创建进程采用API函数CreateProcess实现.下面是一个使用例 ...

  4. 【Linux】修改Linux操作系统字符集与Oracle数据库一致

    #数据库中查看所使用字符集 SQL> select userenv('language') from dual; USERENV('LANGUAGE') -------------------- ...

  5. session 存入redis 或 memcache 的方法

      Session简介 session,中文经常翻译为会话,其本来的含义是 指有始有终的一系列动作/消息,比如打电话时从拿起电话拨号到挂断电话这中间的一系列过程可以称之为一个session.有时候我们 ...

  6. theano和keras安装

    最近在学深度学习框架,要用到keras库,keras可以搭建在tensorflow和theano上,我电脑装的是Windows,因此决定在电脑上搭建theano框架 下面回顾我的安装过程: 1.安装a ...

  7. JQ 获取下一个元素和获取下一个元素的[指定]子元素

    <script type="text/javascript"> $(function () { $("#div1").next().addClass ...

  8. TextInputLayout使用时各个地方的字体颜色

    我们现在在做Android端的输入框时,要具备如下功能: 默认提示获取焦点时提示上移至输入框顶部获取焦点时输入框有提示错误时增加错误提示直接上图: 默认情况: 获取焦点时: 开始输入文字时: 有错误时 ...

  9. Django 框架入门

    1.创建虚拟环境.(如果你想在你的服务器中运行多个项目,那么装虚拟环境是最好的选择) pip install virtualenv pip install virtualenvwrapper 安装好后 ...

  10. PAT_A1136#A Delayed Palindrome

    Source: PAT_A1136 A Delayed Palindrome (20 分) Description: Consider a positive integer N written in ...