LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 03-12-2014, 02:06 AM   #1
D1ver
Member
 
Registered: Jan 2010
Distribution: Slackware 13.37
Posts: 598
Blog Entries: 3

Rep: Reputation: 195Reputation: 195
Dynamically generating /etc/network/interfaces file every time ifupdown is run


Hello,

I'm working on an embedded Linux project and I'm having a little problem trying to handle user-configurable interface settings. The device is running emdebian and networking is handled by ifupdown.


The goal is to have a website where a user can chose either DCHP mode or static mode, and configure the static IP, gateway, netmask etc.

I've set up the following /etc/network/interfaces file
Code:
auto lo
iface lo inet loopback 

auto eth0
iface eth0 inet static
        address $(/root/ethernet.sh address)
        gateway $(/root/ethernet.sh gateway)
        netmask $(/root/ethernet.sh mask)
Where /root/ethernet.sh is a script that returns the user configured parameters (EG. '/root/ethernet.sh address' returns 10.10.6.100).

This configuration works fine. However if I try to expand it to include the option for DHCP it doens't seem like I'm able to dynamically generate the 'iface eth0 inet static' line. For example if I use the following

Code:
auto eth0
$(echo "iface eth0 inet static")
ifup complains about misplaced options.

If I try
Code:
 
$(echo -e "auto eth0 \n iface eth0 inet static")
ifup complains about unknown interface eth0.

Anyone have any ideas? I'm also open to better ways to do this..

Last edited by D1ver; 03-12-2014 at 02:16 AM.
 
Old 03-12-2014, 10:05 AM   #2
nikmit
Member
 
Registered: May 2011
Location: Nottingham, UK
Distribution: Debian
Posts: 178

Rep: Reputation: 34
This might be rather obvious, but why don't you directly adjust the content of /etc/network/interfaces and then run ifupdown?

When your user submits the web form containing the settings, your CGI should create a new interfaces file with the supplied information and then apply them by restarting networking.

Last edited by nikmit; 03-12-2014 at 10:17 AM.
 
Old 03-12-2014, 07:11 PM   #3
D1ver
Member
 
Registered: Jan 2010
Distribution: Slackware 13.37
Posts: 598

Original Poster
Blog Entries: 3

Rep: Reputation: 195Reputation: 195
Can't see the forest for the trees sometimes I guess.

I didn't really consider regenerating the whole interfaces file because I wanted ifupdown to trigger the system to go fetch the configurable data, but if I can ensure that the interfaces file is updated correctly whenever the user submits changes then I guess that will work fine.

Cool, cheers.
 
  


Reply


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
ifup: couldn't read interfaces file "/etc/network/interfaces" dobharweim Linux - Networking 1 12-13-2013 12:20 PM
Is it possible to run the interfaces file after modifying? nhammoud Linux - Networking 4 01-27-2011 11:14 AM
How can I get wvdial run form /etc/network/interfaces gandrusz Linux - Wireless Networking 1 12-29-2010 11:38 AM
ifup: couldn't read interfaces file "/etc/network/interfaces" debian lenny lorimer73 Linux - Networking 1 08-24-2010 04:47 PM
problem with network interfaces during boot time kylnas Linux - Hardware 3 08-15-2003 08:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:24 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