LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 11-19-2014, 12:52 PM   #1
baconisbetter
LQ Newbie
 
Registered: Aug 2012
Posts: 26

Rep: Reputation: Disabled
Network script on start


I have a debian box that seems to have lost iface. iface returns command not found, I can't find it anywhere, and my environment is default. I've edited the /etc/network/interface file a ton and no change is ever reflected either through reboots, nor network restarts. When my box reboots, I have to log into the console to set the ip address and routes like so:

ip addr add 192.168.12.35/24 brd + dev eth0
route add default gw 192.168.35.1 eth0

What I'd like to do is one of two things. Add a startup script to run these commands on boot, or figure out what the hack happened to iface. Either solution would be helpful. I've read this page in init.d scripts, but can't really figure out where to add thise two commands: https://mkaz.com/2013/07/03/run-scri...art-on-debian/

Any idea's?
 
Old 11-19-2014, 01:16 PM   #2
Teufel
Member
 
Registered: Apr 2012
Distribution: Gentoo
Posts: 616

Rep: Reputation: 142Reputation: 142
As root:
Code:
echo "#!/bin/bash" > /etc/init.d/networkstart
echo "ip addr add 192.168.12.35/24 brd + dev eth0" >> /etc/init.d/networkstart
echo "route add default gw 192.168.35.1 eth0" >> /etc/init.d/networkstart
chmod +x /etc/init.d/networkstart
update-rc.d networkstart defaults
service networkstart start
Check your second command for typo: 192.168.35.1 seems wrong.
 
Old 11-19-2014, 01:28 PM   #3
baconisbetter
LQ Newbie
 
Registered: Aug 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
I already tried putting those two commands in a bash script called 'ipassignment' in /etc/init.d, then running 'update-rc.d ipassignment defaults'. I tested with a reboot and it just reported as failed. It also had warning during the 'update-rc.d ipassignment defaults' command I assume because I had no call for {start|stop} in the script. I can't reboot that server right now, but when I can I'll grab a screenshot. Running the script itself works, but on boot it failed. Nice catch on the IP addresses as well, I just inserted random numbers insted of the real subnets.
 
Old 11-19-2014, 07:32 PM   #4
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

I don't know what you are talking about with your reference to "iface". If you want a static network interface in debian you don't need to write any scripts, instead you put a few lines in your /etc/network/interfaces file. For example it looks like you want:
Code:
auto eth0
iface eth0 inet static
  address 192.168.12.35
  gateway 192.168.35.1
The "auto eth0" line will ensure the interface is bought up at boot. You can manually start and stop it with "ifup eth0" and "ifdown eth0".

For more information see the interfaces man page and/or Section 8.2.1, example 8.2 in the Debian Administrator's Handbook. http://debian-handbook.info/browse/s...rk-config.html

Evo2.
 
Old 11-19-2014, 11:07 PM   #5
Teufel
Member
 
Registered: Apr 2012
Distribution: Gentoo
Posts: 616

Rep: Reputation: 142Reputation: 142
There is anothere (and more simple) way to run script at startup: add a line in /etc/rc.local:
Code:
/PATH/TO/YOUR/SCRIPT &
Do not forget "&" at the end.
However, the best approach is to configure you interface properly, as evo2 suggested.
 
Old 11-20-2014, 08:50 AM   #6
baconisbetter
LQ Newbie
 
Registered: Aug 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
I'll give this a shot. As far as I can tell I do have my interface configured correctly, however changes I make to the /etc/networking/interfaces file are never reflected. Regardless of system reboot or stopping and starting the networking service, it never works, on either interface. If I use the two commands posted in my first post, I can manipulate the interfaces with no issue. Unless "eth0" and "eth1" aren't the correct identifiers, then I'm at a loss.
 
Old 11-20-2014, 07:56 PM   #7
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,
Quote:
Originally Posted by baconisbetter View Post
I'll give this a shot. As far as I can tell I do have my interface configured correctly, however changes I make to the /etc/networking/interfaces file are never reflected.
Debian does not use that file. You need to edit /etc/network/interfaces.

Quote:
Originally Posted by baconisbetter View Post
Regardless of system reboot or stopping and starting the networking service, it never works, on either interface.
What "networking service". Perhaps you are thinking of RHEL based systems?

Quote:
Originally Posted by baconisbetter View Post
If I use the two commands posted in my first post, I can manipulate the interfaces with no issue. Unless "eth0" and "eth1" aren't the correct identifiers, then I'm at a loss.
You are using a Debian system, so please use the infrastructure it provides. To see what interfaces you have use:
Code:
ifconfig -a
Evo2.
 
Old 11-20-2014, 09:27 PM   #8
baconisbetter
LQ Newbie
 
Registered: Aug 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by evo2 View Post
Hi,

Debian does not use that file. You need to edit /etc/network/interfaces.
My mistake on the typo, it is /etc/network/interfaces that im editing with no reflected change.
Quote:
What "networking service". Perhaps you are thinking of RHEL based systems?
I do generally work in RHEL systems, so what i mean is if i do this:
Code:
/etc/init.d/networking start/stop
Does this not restart the network service? since I use the word 'networking' in the command, so I called it the 'networking service', what should I call it?
Quote:
You are using a Debian system, so please use the infrastructure it provides. To see what interfaces you have use:

Code:
ifconfig -a
I try to but it does nothing. In fact, I can use ifconfig to assign an address to either eth0 or eth1, but it fails to pick up anything in /etc/network/interfaces. here is my ifconfig output:
Code:
eth0      Link encap:Ethernet  HWaddr 00:50:56:80:5a:55
          inet addr:192.168.12.35  Bcast:192.168.12.255  Mask:255.255.255.0
          inet6 addr: fe80::250:56ff:fe80:6b54/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:18990228 errors:0 dropped:0 overruns:0 frame:0
          TX packets:36263342 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3852479854 (3.5 GiB)  TX bytes:41864623301 (38.9 GiB)

eth1      Link encap:Ethernet  HWaddr 00:50:56:80:4c:43
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:342426 errors:0 dropped:0 overruns:0 frame:0
          TX packets:342426 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:35961380 (34.2 MiB)  TX bytes:35961380 (34.2 MiB)

pan0      Link encap:Ethernet  HWaddr 92:4c:ff:dd:57:59
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
Here is my /etc/network/interfaces:
Code:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth1 inet static
        address 192.168.12.35
        netmask 255.255.255.0
        network 192.168.12.0
        broadcast 192.168.12.255
        gateway 192.168.12.1
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 192.168.25.118 192.168.26.203
        dns-search co.int

allow-hotplug eth1
iface eth1 inet static
        address 192.168.25.21
        netmask 255.255.255.0
        network 192.168.25.0
        broadcast 192.168.25.255
        gateway 192.168.25.2
        dns-nameservers 192.168.25.118 192.168.26.203
        dns-search co.int
Now, if i reboot, or do a '/etc/init.d/networking stop/start', both interfaces come back with NO ip address, and the system has no default route until I log onto the console and do:
Code:
ip addr add 192.168.12.35/24 brd + dev eth0
route add default gw 192.168.12.1 eth0
Only then does everything come back online.
 
Old 11-20-2014, 09:34 PM   #9
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

you have two eth1 sections in your interfaces file and no eht0 section.

Evo2.
 
Old 11-20-2014, 09:39 PM   #10
baconisbetter
LQ Newbie
 
Registered: Aug 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
that's another typo. I was going through the post checking it all and changed that think it was wrong and just logged back into the server thinking I'd found something. the one on the server is:
Code:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
        address 192.168.12.35
        netmask 255.255.255.0
        network 192.168.12.0
        broadcast 192.168.12.255
        gateway 192.168.12.1
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 192.168.25.118 192.168.26.203
        dns-search co.int

allow-hotplug eth1
iface eth1 inet static
        address 192.168.25.21
        netmask 255.255.255.0
        network 192.168.25.0
        broadcast 192.168.25.255
        gateway 192.168.25.2
        dns-nameservers 192.168.25.118 192.168.26.203
        dns-search co.int
I also have a backup file I;ve tried to use several times that doesn't even have a eth1 section:

Code:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
        address 192.168.12.35
        netmask 255.255.255.0
        network 192.168.12.0
        broadcast 192.168.12.255
        gateway 192.168.12.1
        # dns-* options are implemented by the resolvconf package, if installed
        dns-nameservers 192.168.25.118 192.168.26.203
        dns-search co.int
this is because this host is a vm and I can add and remove NIC cards easily. When nothing was working i added the NIC eth1 for testing.

sorry for the confusion. I also have another one that is strictly for eth1 as a test. none work.
 
Old 11-20-2014, 09:45 PM   #11
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,
Quote:
Originally Posted by baconisbetter View Post
I do generally work in RHEL systems, so what i mean is if i do this:
Code:
/etc/init.d/networking start/stop
Does this not restart the network service? since I use the word 'networking' in the command, so I called it the 'networking service', what should I call it?
Running that with the "start" argument will run "ifup -a" which will call "ifup ethX" for every "ethX" that is marked as "auto" in the interfaces file. This is why I said to run "ifup eth0" If you had have done that I think you would have gotten an error message indicating the problem with your interfaces file (as in my previous post). With the "stop" argument it runs "ifdown -a" which runs "ifdown ethX" for all interfaces marke auto.

Note also that you have not defined your interfaces as auto (you have allow-hotplug).

Evo2.
 
Old 11-20-2014, 09:49 PM   #12
baconisbetter
LQ Newbie
 
Registered: Aug 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
aah I see. OK I don't have console access to this server right now, only ssh, so I'll try this first thing tomorrow when I'm near it again. thanks very much. will the error be verbose or will it be in /var/log/messages?
 
Old 11-20-2014, 09:54 PM   #13
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,
Quote:
Originally Posted by baconisbetter View Post
aah I see. OK I don't have console access to this server right now, only ssh, so I'll try this first thing tomorrow when I'm near it again. thanks very much. will the error be verbose or will it be in /var/log/messages?
Since you said that having two eth1 sections and no eth0 section was just a typo in your post, there probably won't be an error. You just need to run "ifup eth0" and "ifup eth1" to start the networking. To have the interfaces come up by running "/etc/init.d/networking start" (and therefore automatically at boot) you should replace the "allow-hotplug ethX" lines with "auto ethX".

HTH,

Evo2.
 
Old 11-21-2014, 02:04 PM   #14
baconisbetter
LQ Newbie
 
Registered: Aug 2012
Posts: 26

Original Poster
Rep: Reputation: Disabled
I made the changes but it didn't work. We ended up reinstalling a package called netbase to get things working. Thanks for all the help! I did leave the lines at "auto eth0" however.
 
  


Reply



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
start script bash when system start,stop,reeboot, how ?? melmar Linux - General 4 12-10-2009 06:58 AM
Start and stop a bash script based on network activity? creativetweak Linux - Software 8 05-04-2008 10:28 PM
Interrupt driven script for network start and stop MrUmunhum Linux - Networking 7 01-13-2008 06:24 PM
Script to start network connection? {e} Linux - General 7 08-05-2007 06:00 AM
How can I create a script to start my network? asdfjkl Linux - Wireless Networking 3 08-12-2004 09:12 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 01:36 AM.

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