Bug 11309

Summary: ifup-post destroys local nameserver info in resolv.conf
Product: [Retired] Red Hat Linux Reporter: Barry Alcock <alcockba>
Component: initscriptsAssignee: Bill Nottingham <notting>
Status: CLOSED WONTFIX QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 6.2CC: bradley.g.smith, rvokal
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2005-02-15 20:53:56 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Barry Alcock 2000-05-08 21:54:05 UTC
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 21:57:59 UTC
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 16:25:59 UTC
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 21:24:59 UTC
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 19:04:57 UTC
Fixing status, was 'REOPENED NOTABUG'.

Comment 5 Brad Smith 2003-12-03 19:09:08 UTC
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 20:53:56 UTC
Closing out bugs on older, no longer supported releases.

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