You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.4 KiB
Bash
56 lines
1.4 KiB
Bash
#!/bin/bash
|
|
|
|
# Print the ip address of the raspberry pi
|
|
current_ip=$(hostname -I | cut -d' ' -f1)
|
|
|
|
# Print the ip address
|
|
echo "The current ip address is $current_ip"
|
|
|
|
# Ask if they want to change the ip address
|
|
echo -n "Do you want to change the ip address? (Y/n) "
|
|
read change_ip
|
|
|
|
# Exit if they don't want to change the ip address
|
|
if [ "$change_ip" = "n" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
# Ask if they want to use dhcp
|
|
echo -n "Do you want to use dhcp? (y/N) "
|
|
read use_dhcp
|
|
if [ "$use_dhcp" = "y" ]; then
|
|
# Set the ip address to dhcp
|
|
sudo nmcli device modify eth0 ipv4.method auto
|
|
|
|
# Restart the network
|
|
sudo nmcli c down "Wired connection 1"
|
|
sudo nmcli c up "Wired connection 1"
|
|
exit 0
|
|
fi
|
|
|
|
# Ask for the new ip address
|
|
echo -n "Enter the new ip address: "
|
|
read new_ip
|
|
|
|
# Ask for the new subnet mask
|
|
echo -n "Enter the new CIDR subnet mask (press enter for default of 24) "
|
|
read subnet_mask
|
|
if [ -z "$subnet_mask" ]; then
|
|
subnet_mask="24"
|
|
fi
|
|
|
|
# Ask for the new gateway
|
|
echo -n "Enter the new gateway (press enter for default of 192.168.25.1) "
|
|
read gateway
|
|
if [ -z "$gateway" ]; then
|
|
gateway="192.168.25.1"
|
|
fi
|
|
|
|
# Set the new ip address
|
|
sudo nmcli c mod "Wired connection 1" ipv4.addresses $new_ip/$subnet_mask ipv4.method manual
|
|
sudo nmcli c mod "Wired connection 1" ipv4.gateway $gateway
|
|
|
|
# Restart the network
|
|
sudo nmcli c down "Wired connection 1"
|
|
sudo nmcli c up "Wired connection 1"
|