Caurse some of my friends have bought this modem fro 3.dk – they still wanted to be able to have more than one Computer on the internet – and have been told from 3 – that it was possible to buy a router that could handle that – for 4000danish kt. Way to much – At the same time they bougth a house in the country where 3 had no good coverage – so we needed to make this work untill they could get rid of the 3G modem – so here’s what I did:
I started out with moving my mailserver from my Lexcom lexligth and installed Ubuntu Gutsy 7.10 on it.
Started out after the install by editing /etc/apt/sources.list and enabled all repos in that file ( Not enabled as standard). Afterwards I installed the following packages for being able to make it all work:
$ apt-get update $ apt-get install openssh-server dhcp bind9 wvdial |
The DHCP-server is quite easy – but needed to fill in the info about the DNS server in the conf-file – so I’d made at subnet internal for them in the range: 172.16.7.0/24 – that’ll means they got 254 IP adresses on their sybnet. I ended up with a configurationfile for the DHCP-server looking like this:
# # Sample configuration file for ISC dhcpd for Debian # # $Id: dhcpd.conf,v 1.4.2.2 2002/07/10 03:50:33 peloy Exp $ ## option definitions common to all supported networks… option domain-name “example.com”; option domain-name-servers 80.251.192.244; option domain-name-servers 80.251.192.245; option subnet-mask 255.255.255.0; subnet 172.16.7.0 netmask 255.255.255.0 { #host confusia { |
As you can see here – the range for DHCP adresses are from 172.16.7.2 – 250 !
REMEMBER TO ADD THE DEFAULT INTERFACE TO /etc/default/dhcp
After that worked – I continued further on to getting the modem to work – luckly for me – there was already a guide for that – but still had to make some small changes for it to work. So started out with making the directory where I place all my scripts:
$ mkdir /scripts |
Started out with getting the modemdriver to the huwai modem and placed in the /scripts directory. You can download the driver here
And afterwards made the script for loading the rigth modules,drivers etc! It’ll end up looking like this:
#!/bin/bash # This script is made for using a 3G modem with Ubuntu # Made 20080112 by PBJecho “removing USB-Storage..” rmmod usb-storage sleep 1 echo “Loading modem” echo “Loading driver” echo “Connecting” |
As you can see in that script – we’re ending up with calling the wvdial default configuration – therefor you need to add/edit the /etc/wvdial.conf default section to also holds these informations:
[Dialer default] Phone = *99***1# Username = irrelevant Password = irrelevant Stupid Mode = 1 Dial Command = ATDT Modem = /dev/ttyUSB0 Baud = 460800 Init2 = ATZ Init3 = ATE0V1&D2&C1S0=0+IFC=2,2 ISDN = 0 Modem Type = Analog Modem Init5 =AT+CGDCONT=1,”IP”,”data.tre.dk”; |
This will get the Modem connection to connect to the 3.dk server with a POINT TO POINT connection. But it’ll take around 15-20seconds before the connection is working. and the ligth in it will change from green to blue/violet!
But before that we need to check some things are working correct – we need to make sure the rigth modules etc are there – if there’s not 3 units in /dev/ttyU* – remove the modem – wait 10seconds – plug it in again – run the script: here’s what it should look like:
$ ls -lah /dev/ttyU* crw-rw—- 1 root dialout 188, 0 2008-01-15 13:25 /dev/ttyUSB0 crw-rw—- 1 root dialout 188, 0 2008-01-15 13:25 /dev/ttyUSB1 crw-rw—- 1 root dialout 188, 0 2008-01-15 13:25 /dev/ttyUSB2 |
If there’s not 3 lines – don’t try connecting – it’ll not work!
Now we need to make sure (since it should be a router/firewall) to make sure that the modem also connects after powerfailure etc! So I added these lines into /etc/rc.local:
echo “Starting Scripts for ppp0” /scripts/init_usb_modem.sh & sleep 30 |
Reason for sleep 30 – is when we’re adding the firewall – We’ll have to make sure that the modem connection works – othervise the firewall script will fail – caurse of unknown parameters.
Now reboot your machine – and check the console output to make sure the internet is comming up. If this is working – where ready to add the firewall to the machine.
The script I’d made is this:
#!/bin/bash # # Created by: Per Jørgensen 2007 # Mail: linux@pbj-design.dk # # Revision History # # Version 0.1: Added pppo for Internetconnection # Version 0.0: Started with the script # # ——————————————————————- # Setup the enviroment variables # ——————————————————————- # External Program IPTABLES=”/sbin/iptables”# Setting up the interfaces LO=”lo” WAN=”ppp0″ LAN=”eth0″ #GW=”`ifconfig $WAN | grep \”inet addr\” | cut -f 3 -d \”:\” | cut -f 1 -d \” \”`” GW=”10.64.64.64″ # The IP-addresses for the interfaces #Networks # The machines on the net #——————————————————————- echo echo # ————————————————————— echo ” Done” # Forwarding # Default Policies echo ” Done” ## DNS ## ## ICMP ## echo ” Done. INPUT chain is up and running” # ————————————————————– # Accepting outgoing trafik # Rejecting Ident echo ” Done. OUTPUT chain is up and running” ################################################################ echo ” Done. LO is up and running” # ————————————————————– echo ” Done. LAN is up and running” # ————————————————————– echo ” Done. WAN is up and running” ################################################################ echo ” Done. LANTOWAN chain is up and running” ################################################################ # Accepting only returntraffic to lan echo ” Done. WANTOLAN chain is up and running” ################################################################ echo ” Done. MASQUERADING is up and running” ################################################################## echo “Done. The chains are now activated” echo |
And afterwards add also these lines ion /etc/rc.local in the bottom after sleep 30.
echo “Running firewall.” sh /scripts/firewall.shexit 0 |
Well – now you’re ready to reboot once more – and hopefully everything is working well.
FAQ:
Everything went well – but no internet:
Check out your route table with the command: route -vn
I discovered several times that no default gw was set – instead there was an empty line . So I did this:
$ route del default $ route add default gw 10.64.64.64 |
Which make the default gateway to be the gateway at 3.dk!
But my project was working without an default gateway – and without setting it in the route table.
Now everything should work – and hopefully you be able to get a router working along with a 3G modem.
I have put all the default configurationsfiles and scripts into a tar.gz archive – which can be downloaded here.
Hopefully have fun with it!