Activities

April 2010
M T W T F S S
« Mar   May »
 1234
567891011
12131415161718
19202122232425
2627282930  

How do I add route on Mac OS or Disable internet on MaC for testing offline application

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

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>