Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to create a shell script the gets as first parameter a subnet mask and as the second paramater a GW address.

something like this: "" by running this line I will be able to put the new subnet mask and DW.


share|improve this question
up vote 1 down vote accepted

You have ifconfig for that?

ifconfig eth0 netmask gateway

share|improve this answer
how do I put it in a script to receive argument of and – edotan Mar 13 '12 at 12:29
To just echo what's currently set you could use grep/awk and the like to parse the output of ifconfig, for example ifconfig eth0 | grep "inet addr:"|awk '{print $2}' or if installed you could also use ifdata. ifdata -pa eth0 for IP address ifdata -pn eth0 for netmask. – duenni Mar 13 '12 at 12:52

Your Answer


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.