Playing with network config

August 4, 2010, by | Start Discussion

Oh! By the way we have discussed a lot on Command Line Gyan about advance stuff but are we comfortable with basic settings which we might use daily?

In this issue of command line gyan, let’s play around with IP address configurations

Windows

On a windows box netsh is most powerful utility I have seen. It’s inbuilt in Windows so you don’t have to install something for it. command

C:> netsh

netsh>?

If you remember we used netsh in last issue where we touched upon firewalls and while writing that article I thought of writing about netsh in depth sometime.  To play more with any option just type the option followed by a ‘?’  

netsh> interface

netsh interface> ?

Commands in this context:

?          - Displays a list of commands.
add     - Adds a configuration entry to a table.
delete - Deletes a configuration entry from a table.
dump - Displays a configuration script.
help    - Displays a list of commands.
ip        - Changes to the `netsh interface ip' context.
ipv6    - Changes to the `netsh interface ipv6' context.
portproxy   - Changes to the `netsh interface portproxy' context.
reset    - Resets information.
set        - Sets configuration information.
show    - Displays information.

Let’s see how we can now use netsh to set an IP address of an interface

netsh interface ip> set address ?
Usage: set address [name=]  [[source=]dhcp|static] [[address=][/] [[mask=]
] [[gateway=]|none [gwmetric=]] [[type=]unicast|anycast] [[subinterface=]
] [[store=]active|persistent]                  

Let’s say you want to set an IP 192.168.1.10 on your interface. The gateway to your network of netmask 24bit is 192.168.1.1. So the command will become

set address "Local Area connection" static 192.168.1.10 255.255.255.0 192.168.1.1 1

To make my life easy I always rename my network connections to something like LAN1, LAN2 WIFI1 etc.

That enables me to use this command faster on command line directly such as

C:> netsh interface ip set address name="WiFi" static 
192.168.1.93 255.255.255.0 192.168.1.1 1

or

C:> netsh interface ip set address name="LAN1" source=dhcp

Ok, that’s IP set, what about DNS, can’t go long way without it

C:> netsh interface ip set dnsserver name="LAN1" static 8.8.8.8 primary

Or

C:> netsh interface ip set dnsserver name="WiFi" source=dhcp

Remember, you can create batch files with these commands to run directly and make your work faster & efficient

Damn! This NETSH is still due for a deeper coverage.  

Linux

Ok! as we have always seen Linux is much easier on command line, let’s see how we can achieve the same outputs on Linux.

The first target is to set an IP address on the interface.

# ifconfig eth0 192.168.1.10 netmask 255.255.255.0

The best option here in Linux is that you can fake the MAC address also from command line

To change the mac address

# ifconfig eth0 down
# ifconfig eth0 hw ether DE:AD:CA:FE:BA:BE
# ifconfig eth0 up

If you check the commands carefully, we haven’t yet configured the gateway and DNS server.

DNS in Linux goes through the universal nameservers configured which can be done by nameserver command. To set the gateway in Linux, we’ll have to use route command

# route add default gw 192.168.1.1

You might have noticed that I generally leave the Linux part short. The reason is I want you people to explore the possibilities in Linux cause that’s the way of learning Linux

 
Happy networking 🙂

Rohit Srivastwa

rohit@clubhack.com

 

bio data - Rohit Srivastwa

Leave a Reply