ubuntu/lubuntu setting eth0 (static) and eth1 (dhcp) on start up, every time. (how?)

DeathsDeath

Limp Gawd
Joined
Oct 3, 2010
Messages
395
I am using Lubuntu,

OK I have two Ethernet adaptors on a stand alone box.

I need eth0 to be a static address.
And then eth1 to be dhcp.


- how would i write that as a script (what would it say ....)
- Where would I put it so it is run everytim on start up? (or how would i set it so the system runs the script on start up?)
- It would have to do it everytime the box boots/reboots.


Thanks for looking :)

WHat i have so far :

/etc/network/interfaces
is where the definitions for the eth0/1 are at.

I can set it to:

# eth0 - Static
auto eth0
iface eth0 inet static
address 10.10.10.100
gateway 255.0.0.0
netmask 0.0.0.
network 0.0.0.0
broadcast 0.0.0.0

# eth1 -- DHCP
auto eth0:1
iface eth0:1 inet dhcp


and after this is written in interfaces, I just need to restart it:
sudo /etc/init.d/networking restart

But I need to not have the user have to do this or anything like this and just have it auto do it ...


I am fairly new to this kind of thing and trying to get it to work today ... ideas on how or what to do to make this work :) Thanks!
 
After you've saved the interfaces file and reloaded the networking service, you shouldn't need a script to set it back to that every time your system is rebooted as no user should have access to modify that (or else why do they have sudo rights?). I take it you know the actual addresses you've put in are all incorrect? If not, do you need help configuring that too?
 
so the actuall address (it talks to a control modual via ethernet, on a big Battry back up) so it has to be

ip address:
10.10.10.100
gateway:
255.0.0.0

not sure what else ... everything else we left as zero and worked fine ... am i missing something?
 
eth0 is what talks to the control unit (that is inside the 160 kva unit), and then eth1 host a web interface for them to be able to check the unit if they are not at the unit ... if that makes sense ...
 
You're mistaking the gateway with the netmask. Here's an example of what it could look like. Keep in mind that it will all depend on how your network is laid out.

auto eth0
iface eth0 inet static
address 10.10.10.100
gateway 10.0.0.1
netmask 255.0.0.0
network 10.0.0.0
broadcast 10.255.255.255

auto eth1
iface eth1 inet dhcp
 
looks like you might have done this once or twice :)

what if some one modified eth0 and eth1 and then added a eth2.... is there any way i could clear out every eth0/1/2/3 ect ect before setting eth0 and eth1 ?
 
Unless you have virtual interfaces, you won't have more than however many physical interfaces there are (and then they normally show up as br0 or the likes). You could save a copy of the interfaces somewhere and have it overwrite the current one on boot, but no user will have access to it. If they do, why are you giving them sudo rights? All easily preventable.
 
(sry trying some stuff out with out success...)

Any advice on how to put that into a script.
I need those setting every time I run that script. (or what ever script i end up getting to work right to set those setting)

BTW you rock :)
 
Just delete the old interfaces file, copy the new one from wherever you keep it, and then restart the networking service. Put all the commands in /etc/rc.local

As mentioned previously however, this should be completely unnecessary.
 
Also uninstall NetworkManager. That thing is a PITA. I just finished fighting with that earlier today. It takes over everything.

When I ended up having to do is this config:

Code:
iface eth0 inet static
       address 10.1.2.10
       netmask 255.255.0.0
       network 10.1.0.0
       broadcast 10.1.255.255
       gateway 10.1.1.10

auto eth0

Note the "auto eth0". Important. Otherwise the interface will be turned off by default.

Also in a startup script somewhere:

Code:
echo "nameserver 127.0.0.1" >/etc/resolv.conf
echo "nameserver 10.1.1.10" >>/etc/resolv.conf

Resolv.conf constantly gets overwritten by some other process, which is aparantly part of NetworkManager but despite having uninstalled it, it still gets overwritten. so this was my hackish fix, which works. I stuck that in /etc/rc.local.
 
OK here is what is happeneing, I am using remastersys.

And it freshly installs /etc/ and anything past that ... so i cant permently change it and make a back up and go install it on a diffrent unit becuase then it just sets both eth0 and eth1 to dhcp. (plus if it brought over privious setting it would have old macs witch would be diffent on the new rig.)



So I need to make a script that I can call as I launch my .jar that on its launch it makes sure that (Because with out the static ip it cant talk to the controller board in the unit... witch controls all the power switch for what the unit does, and the dhcp eth1 runs a simple web interface for who ever owns it to be able to just see what the unit is doing)

eth0

and

eth1

Are 0 is static and 1 is dhcp.

if i put it in the home folder and called it to run, it would have to erase anything already there, and then write what is needed and then restart the network devices so the address are right ...

(I feel like i am going in a circle and not making much sense ...)

BTW hope you all had a good 4th :)

and sry if i am completely dumb, just never done anything even close to this, so this is a fly by the seat of your pants type ordeal for me !!!! :)
 
Last edited:
Back
Top