Estou investigando como ter os comandos iproute2 substituindo o antigo comando ifconfig
e ifup
ifdown
e descobri algo interessante.
Minha configuração da NIC é:
[16:07:41 root@vm network-scripts ]# cat /etc/sysconfig/network-scripts/ifcfg-eth2
DEVICE=eth2
ONBOOT=no
BOOTPROTO=dhcp
Para trazer uma interface para cima e para baixo, o caminho antigo será:
%código%
ifup eth2
[16:25:10 root@vm network-scripts ]# ip a show eth2
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 08:00:27:b8:13:b4 brd ff:ff:ff:ff:ff:ff
[16:25:14 root@vm network-scripts ]# ifup eth2
Determining IP information for eth2... done.
[16:25:22 root@vm network-scripts ]# ip a show eth2
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:b8:13:b4 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.4/24 brd 192.168.1.255 scope global eth2
inet6 fe80::a00:27ff:feb8:13b4/64 scope link
valid_lft forever preferred_lft forever
[16:25:26 root@vm-cention network-scripts ]# ifdown eth2
[16:27:51 root@vm-cention network-scripts ]# ip a show eth2
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 08:00:27:b8:13:b4 brd ff:ff:ff:ff:ff:ff
Para usar o comando iproute2 para fazer isso, normalmente usamos ifdown eth2
, mas aparentemente o ip link set eth2 up
só pode exibir a camada de link da NIC, mas não o endereço IP:
[16:36:25 root@vm network-scripts ]# ip link set eth2 up
[16:37:16 root@vm network-scripts ]# ip a show eth2
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:b8:13:b4 brd ff:ff:ff:ff:ff:ff
inet6 fe80::a00:27ff:feb8:13b4/64 scope link
valid_lft forever preferred_lft forever
[16:37:20 root@vm network-scripts ]# ping yahoo.com
ping: unknown host yahoo.com
Mas o tradicional iproute2
pode fazer isso:
[16:37:39 root@vm network-scripts ]# ifup eth2
Determining IP information for eth2... done.
[16:39:59 root@vm network-scripts ]# ip a show eth2
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:b8:13:b4 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.4/24 brd 192.168.1.255 scope global eth2
inet6 fe80::a00:27ff:feb8:13b4/64 scope link
valid_lft forever preferred_lft forever
[16:40:04 root@vm network-scripts ]# ping yahoo.com
PING yahoo.com (98.139.183.24) 56(84) bytes of data.
64 bytes from ir2.fp.vip.bf1.yahoo.com (98.139.183.24): icmp_seq=1 ttl=43 time=243 ms
64 bytes from ir2.fp.vip.bf1.yahoo.com (98.139.183.24): icmp_seq=2 ttl=43 time=341 ms
Acho que isso ocorre porque ifup
exibe a camada de link e também o endereço IPv4 juntos.
Então, minha pergunta é: como usamos o iproute2 para habilitar o endereço IPv4 também ?
Nota:
Curiosamente, quando ifup
desativa a camada de link, ela não desativa o endereço IPv4:
[16:42:50 root@vm network-scripts ]# ip a show eth2
4: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:b8:13:b4 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.4/24 brd 192.168.1.255 scope global eth2
inet6 fe80::a00:27ff:feb8:13b4/64 scope link
valid_lft forever preferred_lft forever
[16:42:58 root@vm network-scripts ]# ip link set eth2 down
[16:43:04 root@vm network-scripts ]# ip a show eth2
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 08:00:27:b8:13:b4 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.4/24 brd 192.168.1.255 scope global eth2
[16:43:09 root@vm network-scripts ]# ping yahoo.com
ping: unknown host yahoo.com