0

I'm working on some software, that runs on a Centos 5.xx installation. I'ts not allowed for our customers to log in to Linux, everything is done from Windows applications, developed by us.

So we have build a frontend for the user to configure network setup: Static/DHCP, ip-address, gateway, DNS, Hostname.

Right now I let the user enter the information in the Windows app, and then write it on the Linux server like this:

  • Write to /etc/resolv.conf: Nameserver
  • Write to /etc/sysconfig/network: Gateway and Hostname
  • Write to /etc/sysconfig/network-scripts/ifcfg-eth0: Ipaddress, Netmask, Bootproto(DHCP or Static) I also (after some time) found out that I was unable to send mail, unless I wrote in /etc/hosts: 127.0.0.1 Hostname

All this seems to work, but is there a better/easier way to do this?

Also, I read the network configuration nearly the same way, but if I use DHCP, I miss som information, for instance the Ip-address. I know that I can get some information from the commandline (ifconfig), but I dont get for instance Hostname, Gateway and DNS. Is there a commandline tool that will display this?

1

You're doing the right thing writing the information, but you'll need to go to the command line to read the information like you said.

the IP is gotten from ip addr show <interface> or ip addr show all and parsing that. ifconfig is the slightly older command for this.

The default gateway is gotten from ip route show as well (route show or netstat -rn gives you the same information in a different format - ip is the newer command for configuring this)

DNS servers are practically always /etc/resolv.conf, so reading that should be fine. /etc/nsswitch.conf is where that is configured... by default /etc/hosts will override your DNS server settings.

Hostname is gotten through running hostname

1

Webmin, probably. Although it being a web-based application I'm not sure it will work gracefully with all network configuration changes.

1

Not sure I'm following the main part of your question, but the last part is fairly easy. There is not 1 program that displays all that you are looking for but, hostname displays the current hostname, netstat -r will display network routing data & the default gateway, if it is set. dig will display the currently used domain name server. Specifically:

dig `hostname` | grep SERVER

should return something like

;; SERVER: 68.94.156.1#53(68.94.156.1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy