dslreports logo
 
    All Forums Hot Topics Gallery
spc
Search similar:


uniqs
12715
mactalla
join:2008-02-19

mactalla

Member

[HOWTO] Connecting to modem through router

This question has come up many times and always seems to be new for people. So I'm making a whole new topic with appropriate subject so this can hopefully be found more easily via search, etc. I will endever to keep this generic to all modem/router/firmware configurations yet also easy to follow step-by-step. Corrections and improvements are welcome.

=== What ===
Modems often permit connecting to them via a web or telnet interface to configure or obtain useful information. When a modem is plugged into a router which then is connected to the computers on the network, the modem cannot be accessed. This How-to explains how to access the modem just like any other computer on the network.

=== Why ===
Especially on these forums, running DMT to connect to the modem (which is done via telnet) is a convenient way to get line stats. This is useful both for an initial setup, but also to audit occasionally. Unplugging the modem to connect directly to it at these times is both troublesome and disruptive to anyone else attempting to access the internet in the same home.

=== How ===
Preparation: A-C

A. First, you need to be able to make changes to the routing. If you walk into your favourite computer store, buy a router and bring it home, you cannot make the necessary changes. For this (and other) reasons, we have custom firmware. Three popular firmwares are: DD-Wrt, OpenWrt and Tomato.

For more information on each of these, see their respective sites:
DD-Wrt: »www.dd-wrt.com
OpenWrt: »www.openwrt.org
Tomato: »www.polarcloud.com/tomato

B. Secondly, you need to know the IP address your modem will respond to. We'll call this $MODEM_IP.
Some known modem IP's:
ST516: 192.168.1.254 and 10.0.0.138
2Wire: 192.168.1.254
DLink 300i: 192.168.1.1 (could be 192.168.0.1 -- I may have changed mine)

C. Finally, you need to know the name of the interface on your router where your modem is plugged in. The modem is usually plugged into the WAN port of the router. See »wiki.openwrt.org/OpenWrtDocs/Configuration for a list of routers and their interface names. We'll call this $WAN_IFACE.
The name of the WAN interface for a few common routers are:
Linksys WRT54GL: vlan1
Linksys WRTSL54GS: eth1
Asus WL-500g: eth1
Asus WL-500g Deluxe/Premium: vlan1

Once you have the information for your particular modem and router, we can configure the router.

Steps: 1-3

1. First, we need to set the interface identified in 'C' to an IP address that is on the same subnet. For example, if the modem is on 192.168.1.254, then we want 192.168.1.pick-a-number (where pick-a-number is not 254 (the modem), or 255 (broadcast), or any other machine on the network. 250 would likely be good. We'll call this $WAN_IP. The command "ipconfig $WAN_IFACE $WAN_IP" should do the trick.

2. Now, we need to update the routing with these two commands:
iptables -A forwarding_rule -d $MODEM_IP -j ACCEPT
iptables -t nat -A POSTROUTING -d $MODEM_IP -j MASQUERADE

3. And of course you want that to happen automatically anytime your router (re)boots. So make a script that does this and have it run on boot.

The exact location to place these commands differs depending on the firmware.

On DD-Wrt routers, place the script files in /jffs/etc/config/
This can be done by ssh'ing into the router and pasting the following lines to the console (set the values on lines 3, 4 and 8 to be correct for your setup):
cd /jffs/etc/config/
echo '#!/bin/sh' > modem.startup
echo 'WAN_IFACE="eth1" # Set this to the name of your WAN port found in step C' >> modem.startup
echo 'WAN_IP="192.168.1.250" # Set this to the IP you selected in step 1' >> modem.startup
echo 'ipconfig $WAN_IFACE $WAN_IP' >> modem.startup
chmod +x modem.startup
echo '#!/bin/sh' > modem.wanup
echo 'MODEM_IP="192.168.1.254" # Set this to the IP address of your modem found in step B' >> modem.wanup
echo 'iptables -A forwarding_rule -d $MODEM_IP -j ACCEPT' >> modem.wanup
echo 'iptables -t nat -A POSTROUTING -d $MODEM_IP -j MASQUERADE' >> modem.wanup
chmod +x modem.wanup
 

Note: the above is slightly modified from »www.dd-wrt.com/wiki/inde ··· guration I would appreciate if anyone running DD-Wrt could confirm here that the above works correctly for you.

On OpenWrt routers, startup scripts are placed in /etc/init.d/
SSH into the router and paste the following commands to the console (set the values on lines 9, 10 and 11 to be correct for your setup):
cd /etc/init.d/
echo '#!/bin/sh' > S52modemroute
echo '' >> S52modemroute
echo '# Get the protocol of the WAN connection' >> S52modemroute
echo 'WANPROTO="$(nvram get wan_proto)"' >> S52modemroute
echo '' >> S52modemroute
echo 'if [  "$WANPROTO" = "pppoe" ]; then' >> S52modemroute
echo '  # Static IP addresses for the modem and WAN device:' >> S52modemroute
echo '  WAN_IFACE="eth1" # Set this to the name of your WAN port found in step C' >> S52modemroute
echo '  WAN_IP="192.168.1.250" # Set this to the IP you selected in step 1' >> S52modemroute
echo '  MODEM_IP="192.168.1.254" # Set this to the IP address of your modem found in step B' >> S52modemroute
echo '' >> S52modemroute
echo '  # Assign a static IP address to the WAN interface' >> S52modemroute
echo '  ipconfig $WAN_IFACE $WAN_IP' >> S52modemroute
echo '' >> S52modemroute
echo '  # Create firewall rules' >> S52modemroute
echo '  iptables -A forwarding_rule -d $MODEM_IP -j ACCEPT' >> S52modemroute
echo '  iptables -t nat -A POSTROUTING -d $MODEM_IP -j MASQUERADE' >> S52modemroute
echo 'fi' >> S52modemroute
chmod +x S52modemroute
 

Note: this works for WhiteRussian. I don't know whether the script needs to be modified for Kamizake -- the only part that might is whether pppoe is still detected via nvram.

On Tomato routers... could someone chime in here? Where do scripts belong?

If you've read this far, hopefully it was helpful. Again, corrections/improvements are welcome!