Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Function to configure the network interface with the static IP
- configure_ip() {
- local aula=$1
- local third_octet=$2
- local fourth_octet=$3
- local ip="10.2.${third_octet}.${fourth_octet}"
- local netmask="255.255.255.0"
- local gateway="10.2.${third_octet}.1"
- echo "Setting up static IP for aula ${aula}..."
- echo "IP Address: ${ip}"
- echo "Netmask: ${netmask}"
- echo "Gateway: ${gateway}"
- # Replace "eth0" with your network interface name
- interface="eth0"
- sudo ip addr flush dev ${interface}
- sudo ip addr add ${ip}/24 dev ${interface}
- sudo ip route add default via ${gateway} dev ${interface}
- echo "Static IP configuration completed for ${interface}"
- }
- # Get user input
- read -p "Enter the aula: " aula
- read -p "Enter the third octet (decimal number): " third_octet
- read -p "Enter the PC number (last octet): " fourth_octet
- # Validate the input
- if ! [[ ${third_octet} =~ ^[0-9]+$ ]] || ! [[ ${fourth_octet} =~ ^[0-9]+$ ]]; then
- echo "Error: Both the third octet and the PC number must be decimal numbers."
- exit 1
- fi
- # Ensure the octets are within valid range
- if [ ${third_octet} -lt 0 ] || [ ${third_octet} -gt 255 ] || [ ${fourth_octet} -lt 1 ] || [ ${fourth_octet} -gt 254 ]; then
- echo "Error: The third octet must be between 0 and 255, and the PC number must be between 1 and 254."
- exit 1
- fi
- # Configure the IP address
- configure_ip ${aula} ${third_octet} ${fourth_octet}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement