Bug 11309 - ifup-post destroys local nameserver info in resolv.conf
ifup-post destroys local nameserver info in resolv.conf
Status: CLOSED WONTFIX
Product: Red Hat Linux
Classification: Retired
Component: initscripts (Show other bugs)
6.2
All Linux
medium Severity medium
: ---
: ---
Assigned To: Bill Nottingham
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2000-05-08 17:54 EDT by Barry Alcock
Modified: 2014-03-16 22:13 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2005-02-15 15:53:56 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Barry Alcock 2000-05-08 17:54:05 EDT
I have one nameserver entry in resolv.conf for the local LAN.

When a ppp connection is brought up the nameserver entries get replaced.
This is fine while the only names to be resolved are external names, but
internal ones cannot get resolved. I need the first nameserver entry to
the local one.

In the script it says awk cannot be relied on. I'm not sure why this is,
but I have written a small awk script and modified network-scripts, ifup-
post and ifdown-post. This works for me. Here is a diff on initscripts-
5.00-1.

--------- cut ---------
diff -u orig/ifdown-post new/ifdown-post
--- orig/ifdown-post	Mon May  8 15:46:40 2000
+++ new/ifdown-post	Mon May  8 21:17:28 2000
@@ -15,6 +15,11 @@
     add_default_route
 fi

+# Reset /etc/resolv.conf
+DNS1=""
+DNS2=""
+update_resolv
+
 # Notify programs that have requested notification
 do_netreport

diff -u orig/ifup-post new/ifup-post
--- orig/ifup-post	Mon May  8 11:32:39 2000
+++ new/ifup-post	Mon May  8 21:17:14 2000
@@ -31,51 +31,10 @@
 if [ "$PEERDNS" != "no" -o "$RESOLV_MODS" != "no" ]; then
   [ -n "$MS_DNS1" ] && DNS1=$MS_DNS1
   [ -n "$MS_DNS2" ] && DNS2=$MS_DNS2
-  if [ -n "$DNS1" ] && ! grep -q "^nameserver $DNS1" /etc/resolv.conf &&
-   tr=`mktemp /tmp/resolv.XXXXXX` ; then
-    # replace only the first two nameserver lines; cannot count on awk
-    # and do not know if sed is capable of this...
-    current_replacement="$DNS1"
-    next_replacement="$DNS2"
-    search=
-    (cat /etc/resolv.conf ; echo EOF ; echo EOF) | while read answer ; do
-	case $answer in
-	    nameserver*|EOF)
-		if [ -n "$current_replacement" ] ; then
-		    echo "nameserver $current_replacement" >> $tr
-		    if [ -n "$next_replacement" ] ; then
-			current_replacement="$next_replacement"
-			next_replacement=
-		    else
-			current_replacement=
-		    fi
-		else
-		    if [ "$answer" != EOF ] ; then
-			echo "$answer" >> $tr
-		    fi
-		fi
-		;;
-	    domain*|search*)
-	        if [ -n "$DOMAIN" ]; then
-	            echo "$answer" | while read key value ; do
-		        search="$search $value"
-		    done
-		else
-		    echo "$answer" >> $tr
-		fi
-		;;
-	    *)
-		echo "$answer" >> $tr
-		;;
-	esac
-	if [ -n "$DOMAIN" ]; then
-	   echo "search $DOMAIN $search" >> $tr
-	fi
-    done
+  if [ -n "$DNS1" ] && ! grep -q "^nameserver $DNS1" /etc/resolv.conf ;
then
+
+    update_resolv

-    # maintain permissions
-    cat $tr > /etc/resolv.conf
-    rm -f $tr
   fi
 fi

diff -u orig/network-functions new/network-functions
--- orig/network-functions	Mon May  8 15:46:40 2000
+++ new/network-functions	Mon May  8 21:21:04 2000
@@ -89,3 +89,48 @@
         fi
     fi
 }
+
+update_resolv ()
+{
+    tr=`mktemp /tmp/resolv.XXXXXX`
+
+    cat /etc/resolv.conf | awk '{		\
+dns1 = "'$DNS1'"; 				\
+dns2 = "'$DNS2'";				\
+fixed = '$FIXED_DNS';				\
+app = 0;					\
+						\
+while (fixed > 0) {				\
+	if ($1 == "nameserver") {		\
+		fixed = fixed - 1;		\
+	}					\
+        print$0;				\
+						\
+	if ( (getline) < 1) {			\
+		app = 1;			\
+		break;				\
+        }					\
+}						\
+						\
+do {						\
+      if (app == 1) {				\
+            if (dns1 != "") {			\
+                printf "nameserver %s\n", dns1;	\
+                dns1 = dns2;			\
+                dns2 = "";			\
+            } else {				\
+                break;				\
+            }					\
+        } else {				\
+            if ($1 != "nameserver") {		\
+                print $0;			\
+            }					\
+            if ( (getline) < 1) app = 1;	\
+        }					\
+    } while (dns1 != "");			\
+}' >$tr
+
+    # maintain permissions
+    cat $tr > /etc/resolv.conf
+    rm -f $tr
+}
\ No newline at end of file
--------- cut ---------
Comment 1 Barry Alcock 2000-05-08 17:57:59 EDT
Almost forgot to mention.

The ifcfg-ppp? files now have an additional entry. FIXED_DNS.
This is the number of nameserver entries to leave alone.
Comment 2 Bill Nottingham 2000-05-16 12:25:59 EDT
You can set PEERDNS=no to not have the resolv.conf
changed; see /usr/doc/initscripts-<version>/sysconfig.txt.

Alternatively, add a 'DNS1' or 'DNS2' entry that
points to your local DNS.
Comment 3 Barry Alcock 2000-05-16 17:24:59 EDT
The problem is that I have 3 possible dialups to the Internet. I wish to use
the DNS servers that are given to me. I want to keep the first DNS server entry
as a primary server used for local lookups. Settings PEERDNS to 'no' or
overriding DNS1 and/or DNS2 will prevent the true Internet DNS servers from
being placed in resolv.conf.
Comment 4 Michael Fulbright 2002-05-26 15:04:57 EDT
Fixing status, was 'REOPENED NOTABUG'.
Comment 5 Brad Smith 2003-12-03 14:09:08 EST
In a closely related problem I have found that when a ppp connection
is "deactivated", the resolv.conf file is not restored to its previous
configuration. I use ppp to connect to a private intranet on occasion
(vpn is not allowed from non-Windows pcs). The ppp activation process
properly adds an internal DNS entry into resolv.conf which maps names
and IPs in the intranet. When the ppp connection is deactivated this
intranet DNS entry remains in resolv.conf as the primary DNS. This
results in sometimes very slow responses to any DNS query as the
primary DNS connection needs to time out before the secondary DNS is
queried. This is with RHEL WS 3.
Comment 6 Bill Nottingham 2005-02-15 15:53:56 EST
Closing out bugs on older, no longer supported releases.

As to the last comment, please reopen a bug for that release if it persists.

Note You need to log in before you can comment on or make changes to this bug.