Latest LQ Deal: Linux Power User Bundle
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-01-2010, 11:49 AM   #1
LQ Newbie
Registered: May 2009
Posts: 27

Rep: Reputation: 16
Question Using ifconfig without using 'ethX'

Hello (and thanks in advance for reading this)

I'm a relatively inexperienced with Linux, coming from a Windows background, and I struggling to solve a troublesome issue attempting to set a static ip address to a Live Debian USB Key. I know it is possible to utilise the 'ifconfig' function to set a static ip address and use 'route' to set the gateway, e.g.

ifconfig eth0 up
route add default gw eth0

..however in both cases I need to explicitly set the 'eth0' to point at the appropriate adapter. However, this is where my problem is...

I'm creating a persistent USB key using the Debian Live CD, I'm going to create an image and then duplicate that image to a load of other USB keys. Again, not a problem as such but there are cases where I need to specify a static IP address and gateway rather than using DCHP.

And here's where problem raises its head.

Because I've created the key on another machine it has allocated 'eth0' to a specific MAC Address (assigned in /etc/udev/70-persistent-net.rules) but when I place it into machine with a different network adapter it is assigning to 'eth1' (and this increments up).

Ideally, if someone could point me in the right direction to either...

a) call 'ifconfig' and 'route' without having to identify the adapter or
b) change the script that is creating '/etc/udev/70-persistent-net.rules' so it overwrites the 'eth0' entry with the only applicavle network adapter for the current hardware.

...or any other solution that would be beneficial. Thank you for your time...

Old 07-01-2010, 12:10 PM   #2
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,236

Rep: Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914Reputation: 914
this mite work [quick-and-dirty]:
device=`ifconfig -a | head -n 1 | awk '{print $1}'`
ifconfig $device up
route add default gw $device
[assuming that the first line in ifconfig -a is the device we care about]
Old 07-01-2010, 12:11 PM   #3
Senior Member
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 249Reputation: 249Reputation: 249
Old 07-01-2010, 01:47 PM   #4
LQ 5k Club
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,577
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
If you delete /etc/udev/70-persistent-net.rules on the key then a new one will be created automatically during boot -- hopefully containing only eth0 for the MAC address of the current computer. If you want to use the key in several computers you could modify the shutdown scripts to delete /etc/udev/70-persistent-net.rules during shutdown.
Old 07-06-2010, 12:22 PM   #5
LQ Newbie
Registered: May 2009
Posts: 27

Original Poster
Rep: Reputation: 16
Hi Everyone,

Thank you to you all for the advice. After some reading and playing the best direction was to simply delete the 70-Persistent file, in this case the file is created again and ties into the eth0 identifier.


Thanks again!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
HowTo Run a script on ifup ethX and a different one for ifdown ethX dscholl Red Hat 3 07-07-2009 02:09 PM
"Ifconfig ethX down" cannot make bonding switch the other NIC. shiner_chen Linux - Networking 0 02-13-2009 04:27 AM
connecting /sbin/ifconfig to bash command ifconfig flammable2 Fedora 4 11-12-2005 08:58 AM
specifying ethX jedediah Linux - Networking 1 09-22-2004 11:00 PM
SUSE ethX-wlan amarchis Linux - Wireless Networking 3 08-27-2004 09:14 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:42 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration