ifconfig(interfaces config)。通常需要以root身份登录或使用sudo来使用ifconfig工具

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

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

ifconfig常见命令参数

Usage:
ifconfig [-a] [-v] [-s] <interface> [[<AF>] <address>]
[add <address>[/<prefixlen>]]
[del <address>[/<prefixlen>]]
[[-]broadcast [<address>]] [[-]pointopoint [<address>]]
[netmask <address>] [dstaddr <address>] [tunnel <address>]
[outfill <NN>] [keepalive <NN>]
[hw <HW> <address>] [metric <NN>] [mtu <NN>]
[[-]trailers] [[-]arp] [[-]allmulti]
[multicast] [[-]promisc]
[mem_start <NN>] [io_addr <NN>] [irq <NN>] [media <type>]
[txqueuelen <NN>]
[[-]dynamic]
[up|down] ...

常用的命令展示

查看当前系统有几个网卡

[root@localhost ~]# ifconfig |grep eth* | awk -F '[ ]+' '{print $1}'

启动关闭指定网卡

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

为网卡配置和删除IPv6地址【临时生效,永久生效需要更改配置文件】

eth2网卡配置文件: /etc/sysconfig/network-scripts/ifcfg-eth2

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

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

为网卡配置和删除IPv4地址【临时生效,永久生效需要更改配置文件】

eth2网卡配置文件: /etc/sysconfig/network-scripts/ifcfg-eth2

[root@localhost ~]# ifconfig eth0 192.168.25.166 netmask 255.255.255.0 up
[root@localhost ~]# ifconfig eth0 192.168.25.166/24 up       【效果同上】
[root@localhost ~]# ip addr add 192.168.25.166/24  dev eth0  【效果同上】

[root@localhost ~]# ifconfig eth0:ws 192.168.25.166 netmask 255.255.255.0 up
[root@localhost ~]# ifconfig eth0:ws 192.168.25.166/24 up       【效果同上】
[root@localhost ~]# ip addr add 192.168.25.166/24  dev eth0:ws  【效果同上】

[root@localhost ~]#ifconfig eth0:ws  192.168.25.166 netmask 255.255.255.0 down
[root@localhost ~]#ifconfig eth0:ws  192.168.25.166/24 dwon     【效果同上】
[root@localhost ~]# ip addr del 192.168.25.166/24  dev eth0:ws  【效果同上】

用ifconfig修改MAC地址

ifconfig eth0 down //关闭网卡
ifconfig eth0 hw ether 00:AA:BB:CC:DD:EE //修改MAC地址
ifconfig eth0 up    //启动网卡 

启用和关闭ARP协议

ifconfig eth0:ws arp 

ifconfig eth0:ws -arp

设置最大传输单元

ifconfig eth0 mtu 1500 

网卡配置文件

网卡eth2对应: /etc/sysconfig/network-scripts/ifcfg-eth2

网卡eth0对应: /etc/sysconfig/network-scripts/ifcfg-eth0

根据网卡名称找对应的文件名称即可

[root@localhost omd]# cat /etc/sysconfig/network-scripts/ifcfg-eth2
HWADDR=00:0c:29:E4:35:5D
TYPE=Ethernet
BOOTPROTO=none
IPADDR=192.168.25.133
PREFIX=24
GATEWAY=192.168.25.2
DNS1=192.168.25.2
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="eth2"
UUID=6e6f9829-0737-4943-ab21-61d6173ba8c4
ONBOOT=yes
LAST_CONNECT=1438160743
DEVICE=eth2
USERCTL=no

网卡的硬件信息

网卡出现乱序,多是因为Mac和网卡名称不一致导致,需要更改此网卡的硬件信息

[root@localhost ~]# cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key. # PCI device 0x1022:0x2000 (vmxnet)
#SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:cc:16:f0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" # PCI device 0x1022:0x2000 (vmxnet)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:e4:35:5d", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"

最新文章

  1. 在公有云AZURE上部署私有云AZUREPACK以及WEBSITE CLOUD(四)
  2. NPOI的使用Excel模板导出
  3. CentOS6 Shell脚本/bin/bash^M: bad interpreter错误解决方法
  4. 【书单】book list
  5. Android学习 之 startActivityForResult 和 onActivityResult
  6. 怎么做QQ、微信等消息气泡
  7. Java最重要的21个技术点和知识点之JAVA基础
  8. 第 7 章 门面模式【Facade Pattern】
  9. HDU 5728 - PowMod
  10. 自定义GridLayout实现条目的拖动动画特效
  11. ogma
  12. Cocos2dx Android环境编译出错:jni/Android.mk: Cannot find module with tag &#39;scripting/lua-bindings&#39; in import path
  13. linux后台执行命令:&amp;与nohup的用法
  14. nodeJS安装和环境变量的配置
  15. 通过read()读文件
  16. loadrunner -27778 https连接问题
  17. IT运维助力业务增值
  18. dev gridview指定单元格cell获取坐标
  19. [小技巧]diff的文件夹忽略使用方式
  20. Pollard rho算法+Miller Rabin算法 BZOJ 3668 Rabin-Miller算法

热门文章

  1. BSDL
  2. 说说java
  3. unity游戏热更新总结
  4. Oracle相关
  5. Python__组合数据类型
  6. [javaEE] http协议详细
  7. iOS原生APP和H5交互-delegate和第三方
  8. 【转】java线程池
  9. HTML列表(组标签)+div(布局标签)与span
  10. Mybatis之reflection包源代码解析(一)