What is the difference between 'ifconfig up eth0' and 'ifup eth0'?
Environment
- Red Hat Enterprise Linux (RHEL) 5
Issue
- What is the difference between 'ifconfig up eth0' and 'ifup eth0'?
Resolution
-
An "ifconfig" command and "ifup" or "ifdown" command can activate network interfaces. "ifconfig" directly controls network interfaces, however "ifup" or "ifdown" executes "/etc/sysconfig/network-scripts/ifup-" or "ifdown-" scripts. The scripts use an ip command.
-
"ifconfig" and "ip" commands use ioctl() to activate or deactivate network interfaces. "ifconfig" flags network interfaces 'IFF_UP | IFF_RUNNING', however "ip" flags that 'IFF_UP'.
-
An "ifconfig up eth0" activates eth0 but does not setup IP addresses, however an "ifup eth0" setup IP addresses or other options based by an ifcfg-eth0, because the "ifup" uses an "ifup-eth*" script.
-
The ifup command will also configure any static routes that are configured in the network-scripts directory. The ifconfig command will not.
Diagnostic Steps
ifconfig.c::main()
473 if (!strcmp(*spp, "up")) {
474 goterr |= set_flag(ifr.ifr_name, (IFF_UP | IFF_RUNNING));
475 spp++;
476 continue;
477 }
478 if (!strcmp(*spp, "down")) {
479 goterr |= clr_flag(ifr.ifr_name, IFF_UP);
480 spp++;
481 continue;
482 }
ifconfig.c::set_flag()
125 /* Set a certain interface flag. */
126 static int set_flag(char *ifname, short flag)
127 {
128 struct ifreq ifr;
129
130 safe_strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
131 if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) {
132 fprintf(stderr, _("%s: unknown interface: %s\n"),
133 ifname, strerror(errno));
134 return (-1);
135 }
136 safe_strncpy(ifr.ifr_name, ifname, IFNAMSIZ);
137 ifr.ifr_flags |= flag;
138 if (ioctl(skfd, SIOCSIFFLAGS, &ifr) < 0) {
139 perror("SIOCSIFFLAGS");
140 return -1;
141 }
142
143 return (0);
144 }
ip/iplink.c::do_set()
254 static int do_set(int argc, char **argv)
255 {
:
267 while (argc > 0) {
268 if (strcmp(*argv, "up") == 0) {
269 mask |= IFF_UP;
270 flags |= IFF_UP;
271 } else if (strcmp(*argv, "down") == 0) {
272 mask |= IFF_UP;
273 flags &= ~IFF_UP;
:
409 if (mask)
410 return do_chflags(dev, flags, mask);
411 return 0;
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments