mirror of
https://github.com/bin456789/reinstall.git
synced 2025-01-19 04:49:13 +08:00
core: 通过默认网关得到默认网卡
This commit is contained in:
parent
ea3dc1ddcf
commit
def42d3277
32
reinstall.sh
32
reinstall.sh
@ -798,19 +798,29 @@ collect_netconf() {
|
|||||||
break
|
break
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
nic_name=$(ip -o addr show scope global | head -1 | awk '{print $2}')
|
# linux
|
||||||
mac_addr=$(ip addr show scope global | grep link/ether | head -1 | awk '{print $2}')
|
# 通过默认网关得到默认网卡
|
||||||
ipv4_addr=$(ip -4 addr show scope global | grep inet | head -1 | awk '{print $2}')
|
for v in 4 6; do
|
||||||
ipv6_addr=$(ip -6 addr show scope global | grep inet6 | head -1 | awk '{print $2}')
|
if ethx=$(ip -$v route show default | head -1 | awk '{print $5}' | grep .); then
|
||||||
ipv4_gateway=$(ip -4 route show default dev $nic_name | awk '{print $3}')
|
mac_addr=$(ip link show dev $ethx | grep link/ether | head -1 | awk '{print $2}')
|
||||||
ipv6_gateway=$(ip -6 route show default dev $nic_name | awk '{print $3}')
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for v in 4 6; do
|
||||||
|
if ip -$v route show default dev $ethx | head -1 | grep -q .; then
|
||||||
|
eval ipv${v}_gateway="$(ip -$v route show default dev $ethx | head -1 | awk '{print $3}')"
|
||||||
|
eval ipv${v}_addr="$(ip -$v -o addr show scope global dev $ethx | head -1 | awk '{print $4}')"
|
||||||
|
fi
|
||||||
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo 1 $mac_addr
|
info "Network Info"
|
||||||
echo 2 $ipv4_addr
|
echo "MAC Address: $mac_addr"
|
||||||
echo 3 $ipv4_gateway
|
echo "IPv4 Address: $ipv4_addr"
|
||||||
echo 4 $ipv6_addr
|
echo "IPv4 Gateway: $ipv4_gateway"
|
||||||
echo 5 $ipv6_gateway
|
echo "IPv6 Address: $ipv6_addr"
|
||||||
|
echo "IPv6 Gateway: $ipv6_gateway"
|
||||||
}
|
}
|
||||||
|
|
||||||
install_grub_win() {
|
install_grub_win() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user