Dec 052006
 

Sponsored Link

You can configure a network interface from the command line using the basic Linux networking utilities. You configure your network client hosts with the command line by using commands to change your current settings or by editing a number of system files. Two commands, ifconfig and route, are used for network configuration. The netstat command displays information about the network connections.

ifconfig Advantages

ifconfig is used to configure your network interface. You can use it to

Activate or deactivate your NIC or change your NIC's mode

Change your machine's IP address, netmask, or broadcast address

Create an IP alias to allow more than one IP address on your NIC

Set a destination address for a point-to-point connection

Using ifconfig with Examples

If you want to find your current ip address you need to enter the following command

ifconfig

Output looks like below

eth0 Link encap:Ethernet HWaddr 00:0F:EA:B2:53:85
inet addr:192.168.2.5 Bcast:192.168.2.255 Mask:255.255.255.0
inet6 addr: fe80::20f:eaff:feb2:5385/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:471 errors:0 dropped:0 overruns:0 frame:0
TX packets:695 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:160637 (156.8 KiB) TX bytes:86193 (84.1 KiB)
Interrupt:185 Base address:0x6000

Create new network alias to a network card (NIC)

Syntax

ifconfig [network device]

Example

ifconfig eth0:1 172.30.49.4

Change IP address

ifconfig eth0 172.30.49.13

Change Subnetmask

Syntax

ifconfig netmask [netmask]

Example

ifconfig eth0 netmask 255.255.255.0

Change broadcast address

Syntax

ifconfig broadcast [address]

Example

ifconfig eth0 broadcast 172.30.49.1

Take interface down

Syntax

ifconfig [network device] down

Example

ifconfig eth0 down

Bring interface up

Syntax

ifconfig [network device] ipaddress up

Example

ifconfig eth0 172.30.49.13 up

If you want to know more information about ifconfig check man page

route command

route is used to build the routing tables (in memory) implemented for routing packets as well as displaying the routing information. It is used after ifconfig has initialized the interface. route is normally used to set up static routes to other networks via the gateway or to other hosts.

route Syntax

route [options] [commands] [parameters]

Examples

To display the routing table, use the route command with no options.

route

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 * 255.255.255.0 U 0 0 0 eth0
default . 0.0.0.0 UG 0 0 0 eth0

Using the -n option to the route command will give the same information, substituting IP addresses for names and asterisks (*), and looks like this

route -n

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
0.0.0.0 192.168.2.1 0.0.0.0 UG 0 0 0 eth0

Add new route

route Syntax

route add default gw ipaddress interface

add a gateway with a specific IP address, you could use the following

route add default gw 172.30.49.1

If you want to know more information about route check man page

Sponsored Link

 Posted by at 9:20 am

  8 Responses to “Network Interface Configuration Using ifconfig”

  1. Hi,i was installed the debian Etch 4.0, and i have a problem with the “ifconfig” command.
    when i’m use this command the line that i wrote below was shown:
    Bash: ifconfig: command no found
    please help me for this eror.
    thanks for your help.

  2. Hello,

    You may need to be under root, to do so, type su and you’ll be asked for the password.
    Hope it help

    Cheers

  3. if it still doesent work as root try this:

    /sbin/ifconfig

    you can also run this command un-rooted on most systems.

  4. Hi;

    Can someone please tell me how to use ifconfig to set address for eth0 from DHCP?

    Thanks.
    I forgot how to do it.
    something like ifconfig eth0 inet dhcp ??
    wont work!

  5. And how to use 2 gateways in the same subnet (with or without failover or/and loadbalance).

    i.e.

    1. Router:
    192.168.1.1

    2. Router:
    192.168.1.254

    Debian-Server:
    192.168.1.3

    And how to use both gateways now on server?

  6. Hi Matey
    [Can someone please tell me how to use ifconfig to set address for eth0 from DHCP?]

    Edit the file /etc/network/interfaces

    # Your primary network interface
    auto eth0
    iface eth0 inet dhcp

  7. Thank You very much Jaelson for the information.

  8. Does anyone know what to do if I’m using a USB ethernet adapter?

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>