Linux: share 3g connection with the internal network


It’s very easy to share an internet connection with iptables and NAT+IP Forward+IP Masquerade. But in my case I needed to share the 3G connection via wifi, and my computer’s nic is not able to work in ad-hoc mode. So I have to use an external wifi router. This router is connected to my Thinkpad R61’s eth0 port, and it needs to obtain its wan IP address via DHCP. So a DHCP server is needed in order to provide the IP and the Gateway for the wifi router.

I coded a simple script as:

/etc/myserver_start.sh

#!/bin/sh

systemctl stop NetworkManager.service

sleep 2

ifconfig eth0 192.168.2.1 up
service dhcpd restart
sleep 2
ifconfig eth0 192.168.2.1 up

sleep 2
wvdial 3g &

sleep 2

/etc/firewall.sh

First relevant line disables the NetworkManager, to avoid the eth0 port gets an IP. eth0 must have an static ip.

Middle lines configures the static IP server address, restart the dhcpd server, and start the 3g connection with wvdial.

Last line launch the firewall (redundant if it is configured as a service).

All the need configurations can be grabbed from:

Linux: DHCP server

Linux: 3G connection with wvdial

Linux: a home firewall

About jjjesss

I'm a guy interested in technology, bsd fan and concerned about the world around.
This entry was posted in Linux. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s