diff --git a/perl-xCAT/xCAT/DBobjUtils.pm b/perl-xCAT/xCAT/DBobjUtils.pm
index 275c8d44d..82dd88c9e 100644
--- a/perl-xCAT/xCAT/DBobjUtils.pm
+++ b/perl-xCAT/xCAT/DBobjUtils.pm
@@ -1938,6 +1938,18 @@ sub getNetwkInfo
 						$nethash{$node}{$attr} = $_->{$attr};
 					}
                                 }
+                                if($nethash{$node}{'gateway'} eq '<myself>')
+                                {
+                                    if(xCAT::NetworkUtils->ip_forwarding_enabled())
+                                    {
+                                        $nethash{$node}{'gateway'} = xCAT::NetworkUtils->my_ip_in_subnet($net, $NM);
+                                    }
+                                    else
+                                    {
+                                        $nethash{$node}{'gateway'} = '';
+                                    }
+                                    $nethash{$node}{'myselfgw'} = 1;
+                                }
                                 next;
                         }
                             
diff --git a/perl-xCAT/xCAT/NetworkUtils.pm b/perl-xCAT/xCAT/NetworkUtils.pm
index eea398de9..0626d6a98 100755
--- a/perl-xCAT/xCAT/NetworkUtils.pm
+++ b/perl-xCAT/xCAT/NetworkUtils.pm
@@ -444,4 +444,79 @@ sub prefixtomask {
     $mask =~ s/(....)/$1/g;
     return $mask;
 }
+
+#-------------------------------------------------------------------------------
+
+=head3  my_ip_in_subnet 
+    Get the facing ip for some specific network
+
+    Arguments:
+       net - subnet, such as 192.168.0.01
+       mask - netmask, such as 255.255.255.0
+    Returns:
+       facing_ip - The local ip address in the subnet,
+                   returns undef if no local ip address is in the subnet
+    Globals:
+    Error:
+        none
+    Example:
+        my $facingip = xCAT::NetworkUtils->my_ip_in_subnet($net, $mask);
+    Comments:
+        none
+=cut
+
+#-------------------------------------------------------------------------------
+sub my_ip_in_subnet
+{
+    my ($class, $net, $mask) = @_;
+
+    if (!$net || !$mask)
+    {
+        return undef;
+    } 
+
+    my $fmask = xCAT::Utils::formatNetmask($mask, 0, 1);
+
+    my $localnets = xCAT::Utils->my_nets();
+
+    return $localnets->{"$net\/$fmask"};
+}
+
+#-------------------------------------------------------------------------------
+
+=head3  ip_forwarding_enabled 
+    Check if the ip_forward enabled on the system 
+
+    Arguments:
+    Returns:
+       1 - The ip_forwarding is eanbled
+       0 - The ip_forwarding is not eanbled
+    Globals:
+    Error:
+        none
+    Example:
+        if(xCAT::NetworkUtils->ip_forwarding_enabled())
+    Comments:
+        none
+=cut
+
+#-------------------------------------------------------------------------------
+sub ip_forwarding_enabled
+{
+
+    my $enabled;
+    if (xCAT::Utils->isLinux())
+    {
+        $enabled = `sysctl -n net.ipv4.ip_forward`;
+        chomp($enabled);
+    }
+    else
+    {
+        $enabled = `no -o ipforwarding`;
+        chomp($enabled);
+        $enabled =~ s/ipforwarding\s+=\s+//;
+    }
+    return $enabled;
+}
+
 1;
diff --git a/xCAT-server/lib/perl/xCAT/Postage.pm b/xCAT-server/lib/perl/xCAT/Postage.pm
index 542f225d2..6bd9f908e 100644
--- a/xCAT-server/lib/perl/xCAT/Postage.pm
+++ b/xCAT-server/lib/perl/xCAT/Postage.pm
@@ -877,6 +877,17 @@ sub net_parms
         my $net  = $_->{'net'};
         my $mask = $_->{'mask'};
         my $gw   = $_->{'gateway'};
+        if($gw eq '<myself>')
+        {
+             if(xCAT::NetworkUtils->ip_forwarding_enabled())
+             {
+                 $gw = xCAT::NetworkUtils->my_ip_in_subnet($net, $mask);
+             }
+             else
+             {
+                 $gw = '';
+             }
+        }
         if (xCAT::NetworkUtils->ishostinsubnet($ip, $mask, $net))
         {
             return ($ip, $mask, $gw);
diff --git a/xCAT-server/lib/xcat/plugins/aixinstall.pm b/xCAT-server/lib/xcat/plugins/aixinstall.pm
index e40db5472..a2da73bf3 100644
--- a/xCAT-server/lib/xcat/plugins/aixinstall.pm
+++ b/xCAT-server/lib/xcat/plugins/aixinstall.pm
@@ -443,6 +443,22 @@ sub process_request
 	my $nimhash   = $flatreq->{'nimhash'};
     my $nodes     = $flatreq->{node};
 
+    my $ip_forwarding_enabled = xCAT::NetworkUtils->ip_forwarding_enabled();
+    foreach my $fnode (keys %{$nethash})
+    {
+        if($nethash->{$fnode}->{'myselfgw'} eq '1')
+        {
+            if ($ip_forwarding_enabled)
+            {
+                $nethash->{$fnode}->{'gateway'} = xCAT::NetworkUtils->my_ip_in_subnet($nethash->{$fnode}->{'net'}, $nethash->{$fnode}->{'mask'});
+            }
+            else
+            {
+                $nethash->{$fnode}->{'gateway'} = '';
+            }
+        }
+     }
+        
     # figure out which cmd and call the subroutine to process
     if ($command eq "mkdsklsnode")
     {
diff --git a/xCAT-server/lib/xcat/plugins/dhcp.pm b/xCAT-server/lib/xcat/plugins/dhcp.pm
index a5504b09e..4c4d6729a 100644
--- a/xCAT-server/lib/xcat/plugins/dhcp.pm
+++ b/xCAT-server/lib/xcat/plugins/dhcp.pm
@@ -1532,6 +1532,18 @@ sub addnet
             if ($ent and $ent->{gateway})
             {
                 $gateway = $ent->{gateway};
+
+                if ($gateway eq '<myself>')
+                {
+                    if(xCAT::NetworkUtils->ip_forwarding_enabled())
+                    {
+                        $gateway = $myip;
+                    }
+                    else
+                    {
+                        $gateway = '';
+                    }
+                }
             }
             if ($ent and $ent->{dynamicrange})
             {
@@ -1707,6 +1719,17 @@ sub gen_aix_net
     my @netent = ( "network $net $mask\n{\n");
     if ( $gateway)
     {
+        if ($gateway eq '<myself>')
+        {
+            if(xCAT::NetworkUtils->ip_forwarding_enabled())
+            {
+                $gateway = $myip;
+            }
+            else
+            {
+                $gateway = '';
+            }
+        }
         if (xCAT::Utils::isInSameSubnet($gateway,$net,$mask,1))
         {
             push @netent, "    option 3 $gateway\n";
diff --git a/xCAT-server/lib/xcat/plugins/networks.pm b/xCAT-server/lib/xcat/plugins/networks.pm
index b6330cafd..f619a8bdc 100644
--- a/xCAT-server/lib/xcat/plugins/networks.pm
+++ b/xCAT-server/lib/xcat/plugins/networks.pm
@@ -276,7 +276,22 @@ sub donets
             		}
             		$ipaddr = $fields[1];
             		$netmask = $fields[2];
-            		$gateway = $fields[6];
+                        if ($fields[6])
+                        {
+                            if(xCAT::Utils::isInSameSubnet($fields[6], $ipaddr, $netmask, 0))
+                            {
+                                $gateway = $fields[6]; 
+                            }
+                        }
+
+                        # set gateway to keyword <myself>,
+                        # to indicate to use the cluster-facing ip address 
+                        # on this management node or service node
+                        if (!$gateway)
+                        {
+                            $gateway = "<myself>";
+                        }
+                        
     
             		# split interface IP
                     my ($ip1, $ip2, $ip3, $ip4) = split('\.', $ipaddr);
@@ -460,11 +475,12 @@ sub donets
             	$net       = $ent[0];
             	$mask      = $ent[2];
 				$mgtifname = $ent[7];
-                if (defined($netgw{$net}{$mask}))
+                if (defined($netgw{'0.0.0.0'}{'0.0.0.0'}))
                 {
-                    $gw =  $netgw{$net}{$mask}; #gateway for this network
-                } else {   
-                    $gw =  $netgw{'0.0.0.0'}{'0.0.0.0'}; #default gatetway
+                    if(xCAT::NetworkUtils->ishostinsubnet($netgw{'0.0.0.0'}{'0.0.0.0'}, $mask, $net))
+                    {
+                        $gw =  $netgw{'0.0.0.0'}{'0.0.0.0'}; #default gatetway
+                    }
                 }
 
 				# use convention for netname attr