So I’m often getting asked how to set up simple networking from the command line.

This drives me nuts a simple google would get the answers!

But, now I can just point people here and save wasting my time.

STATIC
The following presumes you are on a 192.168.1.n class C network with the gateway as 192.168.1.1

Linux

1
2
3
4
5
ifconfig eth0 192.168.1.100 netmask 255.255.255.0 up
route add default gw 192.168.1.1
echo "nameserver 192.168.1.1" >> /etc/resolv.conf
#might need to restart networking
/etc/init.d/network restart

Windows

1
2
3
netsh interface ipv4 show interfaces #in order to identify the name of the interface
netsh interface ipv4 set address name=”Local Area Connection” source=static address=192.168.1.110 mask=255.255.255.0 gateway=192.168.1.1
netsh interface ipv4 add dnsserver name=”Local Area Connection” address=192.168.1.1 index=1

Solaris

1
2
3
4
5
6
7
echo "192.168.1.1" >> /etc/defaultrouter
echo "192.168.1.100 HOSTNAME" >> /etc/inet/hosts
echo "nameserver 192.168.1.1" >> /etc/resolv.
sed -i "s/hosts: file/hosts: dns file/g" /etc/nsswitch.conf
/etc/init.d/network restart
#or just run
/usr/sbin/sys-unconfig #and now reboot and enter details on the console

DHCP
Linux

1
dhclient eth0

Windows

1
netsh interface ipv4 set address name=”Local Area Connection” source=dhcp

Solaris

1
/usr/sbin/sys-unconfig #and now reboot and enter details on the console

Leave a Reply