Problem
User wants to disable internet access and only leave local network for Ubuntu (or any other linux system)
Solution
disable the internet using route del command
IP=$(/sbin/ip route | awk ‘/default/ { print $3 }’)
sudo /sbin/route del default gw “$IP”
echo “$IP” >~/tmp/gw.txt
file will be saved to /tmp/gw.txt to restore the internet connection
cat /tmp/gw.txt
route add default gw <IP address> <NETWORK INTERFACE>
Note:
Please change back to Apostrophes and backticks this is forum issue or using the attached script
Attachment: del_gw.sh
Another option if route del is not possible ( for example ansible fails if no route on some playbooks )
add route to your default network
route add default gw <YOUR IP ADDR> <INTERFACE>
route add default gw 10.50.77.210 ens192
We do this for a living.
Kubernetes, DevOps and platform engineering, delivered in days — not another weekend lost to a stack trace.
Start a project →