connect to internet if a gateway is known

October 15th, 2006 mysurface Posted in ifconfig, Network, route | Hits: 27210 | No Comments »

To check for your IP, you can type

ifconfig

It gives very detail information regarding your network interfaces. For linux, network interface is always eth0, eth1 etc, but for BSD, network interface can be any name. If in the case you doesn’t have any IP for your network interface, and you are given a gateway to connect. You can use ifconfig to configure a static IP for your network interface.

Let say, your network interface is eth0, your gateway is 192.168.1.1 and your network is 192.168.1.0/24 ( that means your network mask is 255.255.255.0 ). You need to configure an IP for you network interface, then adding a default gateway.

Configure your static IP, let say 192.168.1.101,

ifconfig eth0 192.168.1.101 netmask 255.255.255.0 up

Now check whether the IP is configured,

ifconfig eth0

Once it conplete, now add a default gateway using route.

route add default gw 192.168.1.1

The way of IP configuration and adding route might be different from Linux to BSD and other variant of Unix, check the manual for more.

To check the default gateway is it added, type this

route

or

netstat -nr

You will get a line from netstat -nr looks like bellow, ( for linux only)

0.0.0.0         192.168.1.1     0.0.0.0         UG        0 0          0 eth0

Leave a Reply