I have created two scripts which is added on sudo list. One is for removing default gateway and another one is adding the gateway.
1. # vi en_web.sh and add the following line
/sbin/route add -net 0.0.0.0/0 192.168.0.9
2. vi dis_web.sh and add the following lines
/sbin/route delete -net 0.0.0.0/0
3. Add the sudo entry for the user
# visudo , add the lines,save and quit
# Sys-admin added the following lines
User_Alias DEVTEAM = jomon
Cmnd_Alias USERCMD = /Users/jomon/en_web.sh, /Users/jomon/dis_web.sh
DEVTEAM ALL = NOPASSWD : USERCMD
rc-140:~ jomon$ sudo /Users/jomon/dis_web.sh
delete net 0.0.0.0
rc-140:~ jomon$ ping google.com
PING google.com (209.85.231.104): 56 data bytes
ping: sendto: No route to host
ping: sendto: No route to host
ping: sendto: No route to host
ping: sendto: No route to host
^C
— google.com ping statistics —
4 packets transmitted, 0 packets received, 100% packet loss
rc-140:~ jomon$ sudo /Users/jomon/en_web.sh
add net 0.0.0.0: gateway 192.168.0.9
rc-140:~ jomon$ ping google.com
PING google.com (209.85.231.104): 56 data bytes
64 bytes from 209.85.231.104: icmp_seq=0 ttl=55 time=305.435 ms
64 bytes from 209.85.231.104: icmp_seq=1 ttl=55 time=86.583 ms
^C
— google.com ping statistics —
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max/stddev = 86.583/196.009/305.435/109.426 ms
-njoy