Skip to content

Instantly share code, notes, and snippets.

@sarkrui
Last active August 4, 2023 09:07
Show Gist options
  • Save sarkrui/a76bbd5fc27e392f00490ebb9fba439d to your computer and use it in GitHub Desktop.
Save sarkrui/a76bbd5fc27e392f00490ebb9fba439d to your computer and use it in GitHub Desktop.
Change Ethernet IP Address
#!/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
@sarkrui
Copy link
Author

sarkrui commented Jul 31, 2023

ash -c "$(curl -fsSL https://sh.verynerd.workers.dev)" ip.sh 200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment