diff --git a/README.md b/README.md index a5c1cde..27fd4d9 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ Otherwise, you can run this command to revert all changes made by the script: * `--interface ` Manually select a network interface, e.g. eth1 * `--ethx` Disable *Consistent Network Device Naming* to get interface names like *ethX* back * `--ip ` Disable the auto network config (DHCP) and configure a static IP address, e.g. `10.0.0.2`, `1.2.3.4/24`, `2001:2345:6789:abcd::ef/48` + * `--static-ipv4` Disable the auto network config (DHCP) and configure with the current IPv4 address and gateway detected automatically * `--netmask ` e.g. `255.255.255.0`, `ffff:ffff:ffff:ffff::` * `--gateway ` e.g. `10.0.0.1`, `none` if no gateway * `--dns '8.8.8.8 8.8.4.4'` diff --git a/debi.sh b/debi.sh index a629aec..79ab351 100755 --- a/debi.sh +++ b/debi.sh @@ -274,6 +274,14 @@ while [ $# -gt 0 ]; do mirror_host=mirrors.tuna.tsinghua.edu.cn ntp=time.amazonaws.cn ;; + --static-ipv4) + ip=$(ip r get 1.1.1.1 | awk '/src/ {print $7}') + gateway=$(ip r get 1.1.1.1 | awk '/via/ {print $3}') + _cidr=$(ip -o -f inet addr show | grep -w "$ip" | awk '{print $4}' | cut -d'/' -f2) + ip="$ip/$_cidr" + hostname=$(hostname) + interface=$(ip r get 1.1.1.1 | awk '/dev/ {print $5}') + ;; --interface) interface=$2 shift