Introduction:
Since my school project need to set up an ethernet environment. I need to create an internal network under virtualbox. The first step is to setup the gateway inside a virtualbox. After google for a while, I finally setting up my linux as a gateway.
Environment :
linux distribution: alpine linux 2.3
kernel version: 3.0
virtualbox network adapter setting:
1. host-only network=> eth0 for internal network.
2. bridged network => eth1 for internet.
the connection state is like the following figure:
<figure>
<<internet>>----------<<alpine linux>>------------<<internal>>
eth1 pppoe eth0 NAT
The reason why I use alpine linux instead of other distribution is that it is tiny but contains the utilities that to set up my environment.
alpine linux download link:
http://alpinelinux.org/
alpine linux installation guide:
http://wiki.alpinelinux.org/wiki/Installation
Content:
I'll write down all the steps that I configure the internet.
include:
1. package requirement
2. configure the network interface
3. setting up the iptables
4. enable packet forwarding
1.package requirement:
rp-pppoe => pppoe client side program
iptables => firewall
ppp => ppp deamon
that's all.
2.configure the network interface
2.1. the internal network:
configure the /etc/network/interface
add the following line to the file.
auto eth0 iface eth0 inet static address 192.168.56.254 netmask 255.255.255.0 network 192.168.56.0 broadcast 192.168.6.255the address, netmask, network and broadcast can be changed according to you network setting.
2.2.pppoe configuration:
type
pppoe-setting => to start pppoe configuration.
After setting up type
pppoe-connect => connect to the internet via pppoe.
You can check the result by typing:
ifconfig | less
3.setting up the iptables:
type the following command to set the iptables rules:
iptables -A FORWARD -o eth1 -i eth0 -s 192.168.56.0/24 -m conntrack --ctstate NEW -j ACCEPT
iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
iptables -A POSTROUTING -t nat -j MASQUERADE
4.enable packet forwarding:
type
echo 1 > /proc/sys/net/ipv4/ip_forward
type
cat /proc/sys/net/ipv4/ip_forward => check the result.
reference website:
http://wiki.alpinelinux.org/wiki/Alpine_Linux_package_management#Packages_and_Repositories
http://www.linuxfromscratch.org/blfs/view/6.2.0/connect/other.html
http://tldp.org/HOWTO/DSL-HOWTO/configure.html
http://www.brennan.id.au/05-Broadband_Connectivity.html
https://help.ubuntu.com/community/Internet/ConnectionSharing
No comments:
Post a Comment