Linux中ip、ifconfig命令
ifconfig
命令ifconfig是linux系统最为常用的网络工具,可以用于查看网络设置,进而更改网络的参数
[root@rhel-templet ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:DF:59:A4 // link encap 表示网络连接的类型,Ethernet是以太网, HWaddr是网卡的mac地址
inet addr:192.168.2.241 Bcast:192.168.2.255 Mask:255.255.255.0 // Inet addr 是网络的ip地址,Bcast是网络的广播地址, inet6 addr是网络的ipv6的地址
inet6 addr: fe80::20c:29ff:fedf:59a4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 //表示网卡的运行状态
RX packets:290073 errors:0 dropped:0 overruns:0 frame:0
TX packets:77 errors:0 dropped:0 overruns:0 carrier:0 //RX和TX是网卡收发包的情况
collisions:0 txqueuelen:1000 //conllisions表示以太网发生冲突 的次数,如果该值过高,就要考虑可能的网络硬件连接出现的问题
RX bytes:20083764 (19.1 MiB) TX bytes:5719 (5.5 KiB)
Interrupt:11 Base address:0x1400
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:1590 errors:0 dropped:0 overruns:0 frame:0
TX packets:1590 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:1884308 (1.7 MiB) TX bytes:1884308 (1.7 MiB)
设备名lo是一个特殊的设备,每个系统都有它,可叫自循环设备。他可以系统提供一个网络环境,其ip永远为127.0.0.1,掩码为255.0.0.0,而且该设备有系统建立
可以用ifconfig命令更改网络的ip地址:
#ifconfig eth0 192.168.2.3 netmask 255.255.255.0
修改mac地址前,要先停止被修改网卡的服务
#ifconfig eth0 down
#ifconfig eth0 hw ether 00:0A:EB:00:00:01
#ifdown eth0;ifup eth0
ip
基本上,ip命令就是整合了 ifconfig 与 route 这两个指令。不过, ip 可以达成的功能却更多!
<1> ip link
ip link 可以设定与装置 (device) 有关的相关设定,包括 MTU 以及该网路介面的 MAC 等等, 也可以启动 (up) 或关闭 (down) 某个网络的网卡
ip link show 显示全部的网卡信息
ip -s link show eth0 显示详细的eth0端口信息
ip link set eth0 up 启动eth0
ip link set eth0 down 关闭eth0
ip link set eth0 mtu 1000 设置mtu值为1000
ip link set eth0 name mary 设置eth0的标签为mary
ip link set eth0 xx:xx:xx:xx:xx:xx 设置eth0的mac地址
<2> ip addr
ip link设置的是链路层信息,ip addr设置的则是网络层信息
ip addr show 显示当前ip信息
ip addr add xxx.xxx.xxx.xxx/24 dev eth0 label eth0:mary 在eth0上启动ip
ip addr del xxx.xxx.xxx.xxx/24 dev eth0 卸载掉eth0上的ip
<3> ip router
ip router设置的是路由相关的信息
ip router show 显示路由信息
ip router add 192.168.0.12/24 dev eth0 添加路由
ip router del 192.168.0.13/24 dev eth0 删除路由
浙公网安备 33010602011771号