Last active
August 4, 2023 09:07
-
-
Save sarkrui/a76bbd5fc27e392f00490ebb9fba439d to your computer and use it in GitHub Desktop.
Change Ethernet IP Address
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/ash | |
# Check if an argument is passed | |
if [ "$#" -ne 1 ]; then | |
echo "Usage: $0 ip" | |
exit 1 | |
fi | |
ip=$1 | |
# Check if IP is in the range [1..254] and not 2, 99, 88, 98 | |
if ! echo $ip | grep -qE '^(25[0-4]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$' || [ "$ip" = "2" ] || [ "$ip" = "99" ] || [ "$ip" = "88" ] || [ "$ip" = "98" ]; then | |
echo "Invalid IP: $ip. IP should be in the range [1..254] and not 2, 99, 88, 98." | |
exit 1 | |
fi | |
cat << EOF > /etc/network/interfaces | |
iface lo inet loopback | |
auto eth0 | |
iface eth0 inet static | |
address 158.132.58.$ip/24 | |
gateway 158.132.58.2 | |
EOF | |
rc-service networking restart | |
sleep 3 | |
rc-service sockd restart | |
curl -o /dev/null -s -w "%{http_code}\n" google.com |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ash -c "$(curl -fsSL https://sh.verynerd.workers.dev)" ip.sh 200