4

I have a minimal linux installation. The problem is that in order to access the web I have to issue

ifconfig eth0 up
dhclient

after every restart. Where is the canonical place of these commands on an everyday linux system? Or rather where should I put them?

noname
  • 115
  • 2
  • 6

2 Answers2

8

On most modern Linux systems, you should be able to configure the network settings in some config file (Manuel gave some good locations) and the system will take care of executing the relevant commands (like ifconfig and dhclient) for you.

If this is CentOS, you shoud probably set the following in /etc/sysconfig/networking/devices/ifcfg-eth0:

BOOTPROTO=dhcp
ONBOOT=yes

Just to be sure, check also that chkconfig --list network returns something like this:

network         0:off   1:off   2:on    3:on    4:on    5:on    6:off

To start, stop and restart you networking, you can use /etc/init.d/network [start|stop|restart].

Marie Fischer
  • 1,973
  • 1
  • 13
  • 13
  • /etc/init.d/network start brings up the network with nice green [OK] signs. Now the questions cascades -> Where should I put this command? As I don't want to type it after every restart. – noname Jul 26 '09 at 20:58
  • +1 for the essential runlevel configuration of the network init-script. – Manuel Faux Jul 26 '09 at 20:58
  • 1
    @noname: Is the network script enabled in your working runlevel? `chkconfig --list network` will show you, as already mentioned in the answer. If the script is not enabled in runlevel you use to work (maybe 3) you have to switch it on by `chkconfig --level x network on`. – Manuel Faux Jul 26 '09 at 21:02
  • 1
    Just `chkconfig network on` should also work, as the default runlevels for network are 2345. I hope you are not running in single-user mode, are you? To check your default runlevel, look at `/etc/inittab` for a line like this: `id:3:initdefault:`. The 3 in this case is the default runlevel - you should probably be using either 3 (console with networking) or 5 (X-windows). – Marie Fischer Jul 26 '09 at 21:11
  • Wow.. Thanks, solved. You guys are incredibly helpful. :) too bad I can't accept both answers :-/ – noname Jul 26 '09 at 21:12
3

How to configure networking depends on the distribution you use. On a Red Hat based system you will find those configs in /etc/sysconfig/networking/, Debian based systems store them in /etc/network/interfaces, Gentoo stores it in /etc/conf.d/net and Arch Linux like BSD under /etc/rc.conf. Which distribution of GNU/Linux do you use?

The cannonical path to ifconfig is /sbin/ifconfig, but this won't solve your problem, I think.

Manuel Faux
  • 497
  • 3
  • 13
  • This one happened on a RedHat based system, a CentOS. – noname Jul 26 '09 at 20:26
  • 2
    On CentOS you can use `system-config-network` to configure your devices or manually modify `/etc/sysconfig/networking/devices/ifcfg-`. See [the doucmentation](http://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-network-config.html) for more information. – Manuel Faux Jul 26 '09 at 20:30