Linux.com

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 1.2.3.4" > /etc/resolv.conf
# adding 1.2.3.4 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 192.168.0.2/24 dev eth0
# adding 192.168.0.2, subnet mask (255.255.255.0) to my eth card

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

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

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

 

Comments

Subscribe to Comments Feed

Upcoming Linux Foundation Courses

  1. LFD312 Developing Applications For Linux
    05 Jan » 09 Jan - Virtual
    Details
  2. LFS220 Linux System Administration
    05 Jan » 08 Jan - Virtual
    Details
  3. LFD331 Developing Linux Device Drivers
    12 Jan » 16 Jan - Virtual
    Details

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