net-tools和ifconfig
文章目錄
- 歷史關(guān)系
- 兩者使用對比
- 一、顯示所有已連接的網(wǎng)絡(luò)接口
- 二、激活或停用網(wǎng)絡(luò)接口
- 三、為網(wǎng)絡(luò)接口分配IPv4地址
- 四、移除網(wǎng)絡(luò)接口的IPv4地址
- 五、顯示網(wǎng)絡(luò)接口的IPv4地址
- 六、為網(wǎng)絡(luò)接口分配IPv6地址
- 七、顯示網(wǎng)絡(luò)接口的IPv6地址
- 八、移除網(wǎng)絡(luò)設(shè)備的IPv6地址
- 九、改變網(wǎng)絡(luò)接口的MAC地址
- 十、查看IP路由表
- 十一、添加和修改默認(rèn)路由
- 十二、添加和移除靜態(tài)路由
- 十三、查看套接字統(tǒng)計(jì)信息
- 十四、查看ARP表
- 十五、添加或刪除靜態(tài)ARP項(xiàng)
- 十六、添加、刪除或查看多播地址
文章轉(zhuǎn)載 via: http://xmodulo.com/2014/09/linux-tcpip-networking-net-tools-iproute2.html作者:Dan Nanni 譯者:KayGuoWhu 校對:wxy本文由 LCTT 原創(chuàng)翻譯,Linux中國 榮譽(yù)推出https://www.jianshu.com/p/7176c84e328d
歷史關(guān)系
net-tools起源于BSD的TCP/IP工具箱,后來成為老版本Linux內(nèi)核中配置網(wǎng)絡(luò)功能的工具。但自2001年起,Linux社區(qū)已經(jīng)對其停止維護(hù)。同時,一些Linux發(fā)行版比如Arch Linux和CentOS/RHEL 7則已經(jīng)完全拋棄了net-tools,只支持iproute2
作為網(wǎng)絡(luò)配置工具的一份子,iproute2的出現(xiàn)旨在從功能上取代net-tools。net-tools通過procfs(/proc)和ioctl系統(tǒng)調(diào)用去訪問和改變內(nèi)核網(wǎng)絡(luò)配置,而iproute2則通過netlink套接字接口與內(nèi)核通訊。
兩者使用對比
一、顯示所有已連接的網(wǎng)絡(luò)接口
使用
net-tools:
$ ifconfig -a
使用iproute2:
$ ip link show
二、激活或停用網(wǎng)絡(luò)接口
使用net-tools:
$ sudo ifconfig eth1 up
$ sudo ifconfig eth1 down
使用iproute2:
$ sudo ip link set down eth1
$ sudo ip link set up eth1
三、為網(wǎng)絡(luò)接口分配IPv4地址
使用net-tools:
$ sudo ifconfig eth1 10.0.0.1/24
使用iproute2:$ sudo ip addr add 10.0.0.1/24
dev eth1值得注意的是,可以使用iproute2給同一個接口分配多個IP地址,ifconfig則無法這么做。使用ifconfig的變通方案是使用IP別名。
$ sudo ip addr add 10.0.0.1/24 broadcast 10.0.0.255 dev eth1
$ sudo ip addr add 10.0.0.2/24 broadcast 10.0.0.255 dev eth1
$ sudo ip addr add 10.0.0.3/24 broadcast 10.0.0.255 dev eth1
四、移除網(wǎng)絡(luò)接口的IPv4地址
移除網(wǎng)絡(luò)接口的IPv4地址就IP地址的移除而言,除了給接口分配全0地址外,net-tools沒有提供任何合適的方法來移除網(wǎng)絡(luò)接口的IPv4地址。相反,iproute2則能很好地完全。
使用net-tools:$ sudo ifconfig eth1 0使用iproute2:$ sudo ip addr del 10.0.0.1/24 dev eth1
五、顯示網(wǎng)絡(luò)接口的IPv4地址
使用net-tools:$ ifconfig eth1使用iproute2:$ ip addr show dev eth1同樣,如果接口分配了多個IP地址,iproute2會顯示出所有地址,而net-tools只能顯示一個IP地址。
六、為網(wǎng)絡(luò)接口分配IPv6地址
net-tools和iproute2都允許用戶為一個接口添加多個IPv6地址。使用net-tools:$ sudo ifconfig eth1 inet6 add 2002:0db5:0:f102::1/64$ sudo ifconfig eth1 inet6 add 2003:0db5:0:f102::1/64使用iproute2:$ sudo ip -6 addr add 2002:0db5:0:f102::1/64 dev eth1$ sudo ip -6 addr add 2003:0db5:0:f102::1/64 dev eth1
七、顯示網(wǎng)絡(luò)接口的IPv6地址
使用net-tools:
$ ifconfig eth1
使用iproute2:
$ ip -6 addr show dev eth1
八、移除網(wǎng)絡(luò)設(shè)備的IPv6地址
使用net-tools:
$ sudo ifconfig eth1 inet6 del 2002:0db5:0:f102::1/64使用iproute2:
$ sudo ip -6 addr del 2002:0db5:0:f102::1/64 dev eth1
九、改變網(wǎng)絡(luò)接口的MAC地址
使用下面的命令可篡改網(wǎng)絡(luò)接口的MAC地址,請注意在更改MAC地址前,需要停用接口。
使用net-tools:$ sudo ifconfig eth1 hw ether 08:00:27:75:2a:66使用iproute2:$ sudo ip link set dev eth1 address 08:00:27:75:2a:67
十、查看IP路由表
route和netstat。
在iproute2中,使用命令ip route。
使用net-tools:
$ route -n$ netstat -rn
使用iproute2:
$ ip route show
十一、添加和修改默認(rèn)路由
十二、添加和移除靜態(tài)路由
十三、查看套接字統(tǒng)計(jì)信息
十四、查看ARP表
十五、添加或刪除靜態(tài)ARP項(xiàng)
十六、添加、刪除或查看多播地址
作者:阿群1986
鏈接:https://www.jianshu.com/p/7176c84e328d
來源:簡書
簡書著作權(quán)歸作者所有,任何形式的轉(zhuǎn)載都請聯(lián)系作者獲得授權(quán)并注明出處。
總結(jié)
以上是生活随笔為你收集整理的net-tools和ifconfig的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: DNF元素法师加什么?
- 下一篇: go语言如何连接数据库