UPDATE : new version available
windows includes a handy little tool called ‘netsh’. you can use this to completely configure your networking environment from the command line.
and when i say ‘completely’ i mean ‘completely’. you can configure every aspect of windows networking (including ipsec, ras, tcp/ip, rpc a.s.o…). as you can imagine, the commandline for this beast gets rather complex….
i often work in different networking enviroments and have to change my ip configuration very often. for this reason i wanted an easy to use command line tool to quickly change my tcp/ip related configuration (you need 8 mouse clicks and 3 dialogs to do it with the gui, if you are running as admin…i’m not running as admin – so i need even more)
other reasons i wrote this tool were
- i wasn’t quite aware that there are several shortcuts in the netsh syntax to make it more usable
- i wanted to experiment with the .net wmi classes
after sending the tool to keith, he commented that i built something that is already included in the os (yes, every single windows installation – no need to copy my tool on the machine – good point) and that the commandline syntax isn’t that ugly as i thought (and he is partially right here, too). keith now wrote a blog entry about netsh – and i thought i should compare both tools now….
You have to know the name of the network connection (the names in the network connections window) or use ‘lo’ as the standard network interface.
ifconfig /s show all available network interfaces that support tcp/ip and gives you a number. this number can be used in subsequent use with the /eth n switch
setting ip address and subnet mask and default gateway
netsh int ip set addr lo static 192.168.0.23 255.255.255.0 192.168.0.1
ifconfig /eth 1 /ip 192.168.0.23 /mask 255.255.255.0 /gw 192.168.0.1
note : i haven’t found a way to set only the default gw in netsh. in ifconfig that would be:
ifconfig /eth 1 /gw 192.168.0.1
netsh int ip set dns lo static 220.127.116.11 primary
ifconfig /eth 1 /dns 18.104.22.168
switching to dhcp
netsh int ip set addr lo dhcp
ifconfig /eth 1 /dhcp
a ifconfig feature:
use ifconfig /eth 1 /s to show all the wmi has to say about this interface (similar as ipconfig on steroids)
a netsh feature:
keith forgot that.
whats handy in netsh is, that you can dump out your current ip configuration with
netsh int ip dump
e.g. to a text file and reimport that file later with
netsh -f config.txt
that’s a nice feature! i will include that in a future version of ifconfig (but i will just dump out the correct commandline for ifconfig for the current configuration so you can directly use it in batch files :)
the diag stuff keith talks about was new to me and looks reasonable. but it is silly that diag for the mail server is hardwired to outlook express…
other stuff i want to add:
- you can currently only set 1 ip and 1 gateway and 1 dns server (i am thinking about how to implement that without getting to complicated syntax-wise)
- you can’t currently set ip and netmask independently (will be fixed) – but, hey, netsh can’t do that either :)
- turning windows firewall on and off with ifconfig (that’s currently not available in netsh before xp sp2)
- settting the ie proxy (proxies are in general a pain…most often these two config changes go hand in hand – but if you are not running as admin, you have to change the ip config from a admin context, this will not be the context you are running ie in…but the proxy settings are user specific.so i am thinking about that…)
if you want to play around with ifconfig – you can get it here.
if you want to play with netsh – hey – it’s included in windows ;)
if you have any feature suggestions or think thats totally useless – write a comment.
if you think – why doesn’t he just use the mouse – write a comment, too :)