linux:networking
Linux - Networking
This Bash script flushes all IP addresses from a predefined list of network interfaces, then presents a menu allowing the user to configure one of several predefined IPv4/IPv6 address and route setups (while unsetting proxy variables) before exiting.
- Internet_exit_selection.sh
#!/bin/bash # List of interfaces interfaces=("enp5s0" "enp6s0" "enp7s0") # Loop through each interface and flush IP addresses for iface in "${interfaces[@]}"; do echo "Flushing IP addresses from $iface..." ip addr flush dev "$iface" done echo "All specified interfaces have been flushed." # Define the menu options as an array options=("instance1" "instance2" "instance3" "Exit") # Set the prompt for the select statement PS3="Please choose an option: " # Loop indefinitely until the user chooses to exit select choice in "${options[@]}"; do case $choice in "instance1") ip link set enp5s0 up && \ ip -4 addr add 192.168.1.63/31 dev enp5s0 && \ ip -4 route add 0.0.0.0/0 via 192.168.1.62 dev enp5s0 ip -6 addr add 2001:db8:742:c01:151:8888:0:a/96 dev enp5s0 ip -6 route add ::/0 via 2001:db8:742:c01:151:8888:0:1 dev enp5s0 echo "" ip link show enp5s0 ip -4 addr show enp5s0 ip -6 addr show enp5s0 ip -4 route show ip -6 route show unset http_proxy unset https_proxy break ;; "instance2") ip link set enp7s0 up && \ ip -4 addr add 192.168.1.65/31 dev enp6s0 && \ ip -4 route add 0.0.0.0/0 via 192.168.1.64 dev enp6s0 ip -6 addr add 2001:db8:742:c01:152:8888:0:a/96 dev enp6s0 ip -6 route add ::/0 via 2001:db8:742:c01:152:8888:0:1 dev enp6s0 echo "" ip link show enp6s0 ip -4 addr show enp6s0 ip -6 addr show enp6s0 ip -4 route show ip -6 route show unset http_proxy unset https_proxy break ;; "instance3") ip link set enp6s0 up && \ ip -4 addr add 192.168.1.67/31 dev enp7s0 && \ ip -4 route add 0.0.0.0/0 via 192.168.1.66 dev enp7s0 ip -6 addr add 2001:db8:742:c01:153:8888:0:a/96 dev enp7s0 ip -6 route add ::/0 via 2001:db8:742:c01:153:8888:0:1 dev enp7s0 echo "" ip link show enp7s0 ip -4 addr show enp7s0 ip -6 addr show enp7s0 ip -4 route show ip -6 route show unset http_proxy unset https_proxy break ;; "Exit") echo "Exiting menu. Goodbye!" break # Exit the select loop ;; *) echo "Invalid option. Please choose a number from the menu." ;; esac echo # Add a blank line for readability done
linux/networking.txt · Last modified: by jonathan
