LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


Reply
  Search this Thread
Old 05-12-2013, 12:30 PM   #1
Kromitvs
LQ Newbie
 
Registered: May 2013
Posts: 8

Rep: Reputation: Disabled
System wide configuration parameters in configuration files (/etc, e.g.)


Hy,

Although this is my first post, I was unsure to post it in here... so feel free to move it to a better place!


I am searching for a way to use a variable-like system in configuration files from different applications. For instance instead of writing my ip in sshd config file (/etc/configuration-file) and having to change it later, I would just use my-ip variable defined elsewhere. Is there a way todo that for different application configuration files?

I don't even know where or how to start looking for this, so any guidance will be appreciated!

Thanks in advance!
 
Old 05-12-2013, 01:42 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 16,825

Rep: Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408Reputation: 2408
have a look at "/etc/bashrc " or "/etc/profile ( but this should have a warning in it )"

i use a text file "/etc/profile.local "

but this is VERY dependent on just what your os is

or
write a shell script and place it in "/etc/profile.d"
but be VERY careful if you mess it up you might need the install dvd in rescue mode to undo what you did
 
Old 05-12-2013, 04:17 PM   #3
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,275

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
Why would you need to put your IP in your sshd_config file? I've never run accross a case where such a thing would be necessary.
 
Old 05-12-2013, 10:23 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
If you have multiple NICs (inc virtual), then you might want to lock it down to a specific one or few
Code:
     ListenAddress
             Specifies the local addresses sshd(8) should listen on.  The
             following forms may be used:

                   ListenAddress host|IPv4_addr|IPv6_addr
                   ListenAddress host|IPv4_addr:port
                   ListenAddress [host|IPv6_addr]:port

             If port is not specified, sshd will listen on the address and all
             prior Port options specified.  The default is to listen on all
             local addresses.  Multiple ListenAddress options are permitted.
             Additionally, any Port options must precede this option for non-
             port qualified addresses.
http://www.openbsd.org/cgi-bin/man.c...nfig&sektion=5
 
Old 05-16-2013, 06:04 PM   #5
Kromitvs
LQ Newbie
 
Registered: May 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Yes, the idea was to lock sshd to one interface and/or NIC.

And then I started wondering... if I change IP in the future, I will most probably forget about this configuration...

So the "ideal" would be to have a file where general data is kept:
myIP=0.0.0.1
myHostname=workstation

and then be able to use that in configuration files (if one assumes, for instance, I would need to use my IP in another configuration file, maybe this idea becomes clearer)...
 
Old 05-16-2013, 07:47 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
Many people have that set in /etc/hosts; assuming its static, not dhcp.
Sometimes they add key servers as well, so they don't have to relay on DNS always being up, eg during the boot process.
 
Old 05-16-2013, 09:12 PM   #7
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,275

Rep: Reputation: 370Reputation: 370Reputation: 370Reputation: 370
If one's running a web server (or any other sort of server), I would tend to assume a static IP. Unfortunately, I don't know a way to do what the OP wants (doesn't mean it's not possible, just that I don't know how to do it :-)). If, however, the intent is to lock down specific types of traffic to a specific interface, this could be trivially done with iptables (the "-i" flag specifically).
 
Old 05-25-2013, 07:11 PM   #8
Kromitvs
LQ Newbie
 
Registered: May 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Hy again.

I realize this is not an easy question (I've been looking around, and thinking about it: since different configurations files get parsed by different applications, there would have to exist a major standard).

Anyway, thanks for your time!

...however if you wanted to look for this, where/how would you look?
(i haven't found any mention of this subject. I would thing I'm not the only one with this problem...)

Thanks again!

Last edited by Kromitvs; 05-25-2013 at 07:14 PM.
 
Old 05-25-2013, 07:45 PM   #9
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
The point is that (for a static IP), it is often set in eg /etc/hosts or /etc/sysconfig/network or even /etc/sysconfig/network-scripts/ifcfg-eth0 .
It can even be supplied by a DHCP server as a fixed-address.

You could set it in a custom file if you want, but certain programs/services expect to find it in certain places, so only your own custom built SW will find it in a non-std place.

hope that clarifies things.
 
Old 05-30-2013, 08:33 AM   #10
Kromitvs
LQ Newbie
 
Registered: May 2013
Posts: 8

Original Poster
Rep: Reputation: Disabled
Well I'm probably explaining this the wrong way. Let me give an example:
I have app A and B which save their configurations in /etc/a.cfg and /etc/b.cfg.
Booth of them need to know the IP of my machine (in this example, 2.2.2.2).
So:
*/etc/a.cfg
...
ip=2.2.2.2
...

*/etc/b.cfg
...
ip=2.2.2.2
...

But, in a week or so I'll have to change my IP, and I'm almost certain I'll forget to change one of the configurations files.

So, how can I change my IP in only one place and have all configuration files corrected?

I use IP in the example, but I could use some other value that several configuration files need, as an SDK home folder, or... anything really!

Tnks

---------- Post added 30-05-13 at 13:33 ----------


Last edited by Kromitvs; 05-30-2013 at 08:34 AM.
 
Old 05-30-2013, 09:21 AM   #11
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
That is exactly what the /etc/hosts file is for.
 
Old 05-30-2013, 12:02 PM   #12
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 835

Rep: Reputation: 165Reputation: 165
Adding a hosts file entry or running dnsmasq or a name server to translate a host name isn't a universal solution to the OP's question. Not all config files that take an IP address permit the use of a resolvable host name in place of a numeric address. Subnet addresses in many config files have to be specified numerically as well.

I gather that the OPs reference to an IP address was just an example of one possible variable substitution, and what he is really looking for is something more generic that could be used for any kind of substitution in config files. Unfortunaetly, no such thing exists as far as I know.
 
Old 05-30-2013, 12:15 PM   #13
Z038
Member
 
Registered: Jan 2006
Distribution: Slackware
Posts: 835

Rep: Reputation: 165Reputation: 165
Quote:
Originally Posted by Kromitvs View Post
Yes, the idea was to lock sshd to one interface and/or NIC.

And then I started wondering... if I change IP in the future, I will most probably forget about this configuration...

So the "ideal" would be to have a file where general data is kept:
myIP=0.0.0.1
myHostname=workstation

and then be able to use that in configuration files (if one assumes, for instance, I would need to use my IP in another configuration file, maybe this idea becomes clearer)...
The way I keep track of config or other customizable files I've modified so I don't forget about them on an upgrade or a rebuild of my system is to copy them all to a directory under my root home, e.g., /root/upgrade/configs, after I've customized them. Any time I update them in their real location, I make a new copy in my root home configs folder. I also keep a text file to note any directories I add (e.g., in /var/log or whatever) or modify permissions on, and so forth.

Even if my backup copy of the customized files isn't up to date, it's usually no big deal. The main thing is that the list of files serves as a tickler so I know what I might need to update if network or other factors change, or if I upgrade or re-install my system.
 
Old 05-30-2013, 07:41 PM   #14
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
There's 2 (at least) different qns here.
For sshd (and any other pre-built tool/service) you need to use the cfgs & capabilities built into the service ie do it their way.

For your own SW, you can of course create a generic cfg eg /etc/my_custom.cfg and put anything you want in there and have all YOUR SW read that.
However, it can get messy if you start putting stuff in there that only applies to SOME of your progs.


As mentioned above, its a good idea to backup cfgs before you change them.
I generally append the current date eg blah.cfg.YYYYMMDD, which sorts naturally under eg ls. It also enables you to check when you changed something at a glance eg if you start getting weird behaviour, you can see if it started about that time.
 
Old 05-31-2013, 07:18 AM   #15
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Not to mention having to have a parser in each application recognize the parameters for ALL of the applications, even those parameters not used.

Then you have to rebuild all of the applications when you add just one more...

You could try using XML.... but then you also have to put up with the complexity built in just keeping the XML syntax right... So you build an editor to do that...(yet another application), which must also be rebuilt each time you add another application... Or remove one.

And you have recreated the registry of Windows.

Last edited by jpollard; 05-31-2013 at 07:21 AM.
 
  


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
[SOLVED] Equivalent files in Arch configuration of services to Debian configuration... Alexvader Debian 2 10-17-2011 08:44 AM
Your system configuration does not match your Evolution configuration TheIndependentAquarius Linux - Software 2 04-19-2011 05:44 AM
DynDns problem... with configuration or with system configuration? dwhitney67 Linux - Software 1 03-04-2009 11:10 AM
Your system configuration does not match your Evolution configuration ohoh Linux - Software 0 08-19-2004 03:06 PM


All times are GMT -5. The time now is 10:30 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration