Disable outgoing / incoming traffic on Ubuntu
Quote from moshe on 27/10/2020, 12:10 pmProblem
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.txtfile 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
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
Uploaded files:Quote from moshe on 10/11/2020, 1:36 pmAnother 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
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