标签:修改 地址 案例 开启路由转发 ipv4 局域网共享 pos elinks nat实现方式
一、SNAT实现局域网共享IP实现上网
硬件级路由器
硬件级防火墙
iptables -t nat -A POSTROUTING -s 内网IP -j SNAT --to-source 公网IP //适用于静态公网IP地址
iptables -t nat -A POSTROUTING -s 内网IP -j MASQUERADE //适用于动态公网IP地址
二台服务器,一台内网(vmnet1)、一台Linux网关服务器(两块网卡、vmnet1、桥接)
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="no"
ONBOOT="yes"
BOOTPROTO="static"
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=114.114.114.114
/etc/init.d/iptables stop
/etc/init.d/network restart
rm -rf /etc/yum.repos.d/*
vim /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///mnt
gpgcheck=0
mount /dev/cdrom /mnt
yum -y install elinks
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="no"
ONBOOT="yes"
BOOTPROTO="static"
IPADDR=192.168.1.1
NETMASK=255.255.255.0
cp /etc/sysconfig/network-scripts/ifcfg-eth1
vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
NM_CONTROLLED="no"
ONBOOT="yes"
BOOTPROTO="dhcp"
/etc/init.d/iptables stop
/etc/init.d/network restart
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
sysctl -p
iptables -t nat -I POSTROUTING -s 192.168.1.0/24 -j SNAT --to-source 192.168.10.34
内网服务器:elinks www.baidu.com || ping www.baidu.com
发布内部主机,使公网客户端可访问内网
注:DNAT需配合DNS使用,将域名解析到公网IP
硬件级路由器
硬件级防火墙
二台服务器,一台内网(vmnet1)、一台Linux网关服务器(两块网卡、vmnet1、桥接)、实现公网访问内网的ssh
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="no"
ONBOOT="yes"
BOOTPROTO="static"
IPADDR=192.168.1.10
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
DNS1=114.114.114.114
/etc/init.d/iptables stop
/etc/init.d/network restart
vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
NM_CONTROLLED="no"
ONBOOT="yes"
BOOTPROTO="static"
IPADDR=192.168.1.1
NETMASK=255.255.255.0
cp /etc/sysconfig/network-scripts/ifcfg-eth1
vim /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
NM_CONTROLLED="no"
ONBOOT="yes"
BOOTPROTO="dhcp"
/etc/init.d/iptables stop
/etc/init.d/network restart
vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
sysctl -p
iptables -t nat -I PREROUTING -d 192.168.10.231 -p tcp --dport 2333 -j DNAT --to-destination 192.168.1.10:22
公网client:ssh root@192.168.10.231 -p 2333
标签:修改 地址 案例 开启路由转发 ipv4 局域网共享 pos elinks nat实现方式
原文地址:http://blog.51cto.com/13770206/2160845