System wide configuration parameters in configuration files (/etc, e.g.)
Linux - NewbieThis 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!
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
System wide configuration parameters in configuration files (/etc, e.g.)
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!
If you have multiple NICs (inc virtual), then you might want to lock it down to a specific one or few
Specifies the local addresses sshd(8) should listen on. The
following forms may be used:
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.
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).
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...)
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.
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, 22.214.171.124).
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!
---------- Post added 30-05-13 at 13:33 ----------
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.
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:
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.
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.
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.