Home Linux Community Community Blogs Desktops HOWTO: Setup an ethernet card from command line

HOWTO: Setup an ethernet card from command line

Back again with very few commands regarding ethernet configuration.
When you deal with ethernet cards and you don't want to mess around with GUI stuff or utils you need to insert few basic commands to have your working network configuration.

When I'm in a totally new environment and I need to setup an ethernet card on the fly I've a script with few commands for it, I usually don't setup a new profile for the card, expecially if I don't need it or if it's just a test for casual usage. Again, when dealing with Live CD distros designed for special security tasks (my fav is BackTrack :-) ) I type these commands for getting everything done from the command line.
Let's see something:

Setting up the hostname and DNS stuff

# Setup hostname
hostname mycomputerhostname

# Here's a DNS setting
echo "nameserver" > /etc/resolv.conf
# adding as nameserver

When dealing with a live CD distro you don't care about /etc/resolv.conf file but if you're running from your own HD you maybe need to take a backup copy of the file before overriding it (something like cp resolv.conf resolv.backup.conf)

Now let's flush the eth card and setup the new ip address (let's assume we've a /dev/eth0 card to setup)

# Flush every network address for the device /dev/eth0
ip addr flush dev eth0

# Add a new IP address to /dev/eth0 (use the form you want, that's just mine)
ip addr add dev eth0
# adding, subnet mask ( to my eth card

# Let's bring it up and running
ip link set eth0 up

# Now add a default route, in the example
ip route add default via

And that's it !
Here're some basic settings for it, you can compose this material in a script like I did; again, no rocket science here but a very quick howto for command line fans

Next Step: Quick 'n' dirty networking commands

Hope it helps newbies and friends
Glad to read your comments


Andrea (Ben) Benini



Subscribe to Comments Feed

Upcoming Linux Foundation Courses

  1. LFD320 Linux Kernel Internals and Debugging
    10 Nov » 14 Nov - Virtual
  2. LFS426 Linux Performance Tuning
    10 Nov » 13 Nov - Virtual
  3. LFD312 Developing Applications For Linux
    17 Nov » 21 Nov - Virtual

View All Upcoming Courses

Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board