Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Not even sure if i worded this correctly, but here's what I'm trying to do roughly.

Take an IP such as: 192.168.100.0 and mask it to 255.255.255.0, and set the gateway of that route to another IP address.

I'm using bash, on mac os x.

Edit:

To add, IT at my work has an issue where Mac computers have a problem when connecting to a network that has more than one gateway(router). The idea is to create a script that checks to see what subnet it is connected to. If it is the subnet with more than one gateway, then we need to add additional routing rules to ensure proper communication.

Its a few different IPs that will all mask to 255.255.255.0, and all to the same router IP.

for example:

192.168.100.0 mask 255.255.255.0 router/gateway 192.168.160.1

192.168.120.0 mask 255.255.255.0 router/gateway 192.168.160.1

Etc.

share|improve this question

migrated from stackoverflow.com Jul 13 '11 at 2:13

This question came from our site for professional and enthusiast programmers.

    
I re-tagged you should get some more eyes now. Your example above has a gateway that isn't in the network, e.g. 192.168.160.1 is not in 192.168.120.0/24 –  Grady Player Jul 12 '11 at 20:55
    
Thank you, and an interesting point. My knowledge of networking is unfortunately a bit hazy. I haven't done a lot of that stuff since progamming, and I'm more of a web-app developer. –  agmcleod Jul 12 '11 at 21:01
1  
the gateway is how you get out of the local network, eg an address that isn't in 192.168.160.0 if your bitmask is 255.255.255.0, your range of valid addresses is 192.168.160.[0..255] but you shouldn't generally consider 0 to be valid unless your network hardware is set up that way. So an address like 192.168.161.56 will be sent to your gateway address to route properly. –  Grady Player Jul 12 '11 at 21:04
    
This is not really to right question to ask. You should not be having any problems with multiple routers on a network if the network was configured properly, nor should you have to add a series of static routes to the host. Also, doesn't this network have a DHCP server? –  Keith Jul 13 '11 at 2:28
    
Yes, we do have DHCP setup. In terms of the multiple routers, here's a bit of the explanation i got from IT: "The reason for this script is to resolve an issue when connecting the Mac computer to a network with more than one gateway (router). Normally the automatic network configuration sets these settings but when a network has 2 or more gateways additional routing instructions might need to be provided to the computer’s operating system. On Windows based computers these additional routing rules can be applied automatically, but the automatic configuration is not supported on the Mac." –  agmcleod Jul 13 '11 at 17:39
show 2 more comments

2 Answers

for eth0:

sudo ifconfig en0 192.168.100.0 netmask 255.255.255.0

route add default 192.168.100.1 may need to be changed a little if it isn't the default route.

edit: fixed the route, also don't generally use the zero address for a node in the network... unless you know what you are doing.

share|improve this answer
    
You probably meant route add default 192.168.100.1 –  KevinDTimm Jul 12 '11 at 19:30
    
I can understand what your answer means, but I'm not sure what is the question :D . Could you reword the question perhaps to make it more clear? –  bbaja42 Jul 12 '11 at 19:31
    
yeah you are right you are going to need a gateway inside of the /24 network... fixing. –  Grady Player Jul 12 '11 at 19:33
    
Gave that a shot, here's the result output: route: writing to routing socket: File exists add net default: gateway 192.168.160.1: File exists –  agmcleod Jul 12 '11 at 19:35
    
then does it work, can you ping 192.168.160.1? –  Grady Player Jul 12 '11 at 19:39
show 3 more comments
up vote 0 down vote accepted

I spoke to my brother about this, who does networking at his job, sending him the original email. It would seem I explained this rather badly, and I apologize. But essentially, this is what I was looking for:

route add 192.168.100.0 netmask 255.255.255.0 gw $RouterIP

Adding additional routes.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.