我写了一个ip转网口脚本,错在哪里了呢:
见:
[root@node25 xll]# ifconfig
eno1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 34:73:79:17:55:aa txqueuelen 1000 (Ethernet)
RX packets 10196 bytes 1198536 (1.1 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 840 bytes 139440 (136.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xa4b00000-a4bfffff
eno2: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 34:73:79:17:55:ab txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device memory 0xa4900000-a49fffff
ens3f0np0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 10:70:fd:69:af:80 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens3f1np1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.255.153.25 netmask 255.255.255.0 broadcast 10.255.153.255
inet6 fe80::1270:fdff:fe69:af81 prefixlen 64 scopeid 0x20<link>
ether 10:70:fd:69:af:81 txqueuelen 1000 (Ethernet)
RX packets 2384 bytes 210953 (206.0 KiB)
RX errors 0 dropped 71 overruns 0 frame 0
TX packets 1698 bytes 227471 (222.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens6f0np0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
ether 10:70:fd:5d:fc:18 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens6f1np1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.255.153.125 netmask 255.255.255.0 broadcast 10.255.153.255
inet6 fe80::1270:fdff:fe5d:fc19 prefixlen 64 scopeid 0x20<link>
ether 10:70:fd:5d:fc:19 txqueuelen 1000 (Ethernet)
RX packets 641 bytes 41793 (40.8 KiB)
RX errors 0 dropped 71 overruns 0 frame 0
TX packets 26 bytes 1834 (1.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
上面是主机 网卡情况
这是我写的函数
function ip2eth() { ipv4=$1; eth=$(ifconfig | awk -F ":" '/'$ipv4'/{print a}{a=$1}'); echo $eth; }
然后执行:
[root@node25 xll]# ip2eth 10.255.153.25
ens3f1np1 ens6f1np1
返回的竟然是两个网口:ens3f1np1 ens6f1np1 我的脚本错在哪里了呢?