Difference between revisions of "Staging"

From Doge Microsystems
Jump to navigation Jump to search
Line 9: Line 9:
  
 
==== The exact hardware I’ve used ====
 
==== The exact hardware I’ve used ====
* Generic x86_64 PC running Debian 9.5 x86_64
+
* Generic x86_64 PC running Ubuntu Server 18.04
 
* Matrix “MX Modem” (more on this later)
 
* Matrix “MX Modem” (more on this later)
 
* USB to RS232 serial adapter (DE-9) to connect to the modem (Must support hardware flow control)
 
* USB to RS232 serial adapter (DE-9) to connect to the modem (Must support hardware flow control)
Line 18: Line 18:
  
 
==== Software used ====
 
==== Software used ====
* Debian 9.5 x86_64
+
* Ubuntu server 18.04
 
* PPP
 
* PPP
 
* getty
 
* getty
Line 36: Line 36:
 
Full lsusb output:
 
Full lsusb output:
 
<pre>
 
<pre>
user@debian:~# sudo lsusb -v
+
# sudo lsusb -v
 
Bus 004 Device 003: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
 
Bus 004 Device 003: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
 
Device Descriptor:
 
Device Descriptor:
Line 119: Line 119:
 
[Service]
 
[Service]
 
Type=simple
 
Type=simple
ExecStart=/sbin/mgetty -x8 /dev/ttyUSB0
+
ExecStart=/sbin/mgetty /dev/ttyUSB0
 
Restart=always
 
Restart=always
 
PIDFile=/var/run/mgetty.pid.ttyUSB0
 
PIDFile=/var/run/mgetty.pid.ttyUSB0
Line 154: Line 154:
 
<li>Configure ppp by editing <code>/etc/ppp/options</code><br />
 
<li>Configure ppp by editing <code>/etc/ppp/options</code><br />
 
Like above comment out everything except these settings
 
Like above comment out everything except these settings
<pre>#define the DNS server for the client to use
+
<pre># Define the DNS server for the client to use
 
ms-dns 8.8.8.8
 
ms-dns 8.8.8.8
#async character map should be 0
+
# async character map should be 0
 
asyncmap 0
 
asyncmap 0
#require authentication
+
# Require authentication
 
auth
 
auth
#Use hardware flow control
+
# Use hardware flow control
 
crtscts
 
crtscts
#We want exclusive access to the modem device
+
# We want exclusive access to the modem device
 
lock
 
lock
#show pap passwords in log files to help with debugging
+
# Show pap passwords in log files to help with debugging
 
show-password
 
show-password
#require the client to authenticate with pap
+
# Require the client to authenticate with pap
 
+pap
 
+pap
#if you are having trouble with auth enable debugging
+
# If you are having trouble with auth enable debugging
 
debug
 
debug
#heartbeat for control messages, used to determine if the client connection has dropped
+
# Heartbeat for control messages, used to determine if the client connection has dropped
 
lcp-echo-interval 30
 
lcp-echo-interval 30
 
lcp-echo-failure 4
 
lcp-echo-failure 4
#cache the client mac address in the arp system table
+
# Cache the client mac address in the arp system table
 
proxyarp
 
proxyarp
 +
# Disable the IPXCP and IPX protocols.
 +
noipx
 
</pre></li>
 
</pre></li>
 
<li>Create a device option file by editing <code>/etc/ppp/options.ttyUSB0</code><br />
 
<li>Create a device option file by editing <code>/etc/ppp/options.ttyUSB0</code><br />
Line 188: Line 190:
 
</pre>
 
</pre>
 
</li>
 
</li>
<li>Create the user used for PAP authentication<br /><code>useradd -G dialout,dip,users -m -g users -s /usr/sbin/pppd dial</code></li>
+
<li>Create the user used for PAP authentication<br /><code>sudo useradd -G dialout,dip,users -m -g users -s /usr/sbin/pppd dial</code></li>
<li>Change the password (I set it to dial)<br /><code>passwd dial</code></li>
+
<li>Change the password (I set it to dial)<br /><code>sudo passwd dial</code></li>
 
<li>Edit <code>/etc/ppp/pap-secrets</code> and append the username and password (quotes included)<br /> <code>dial    *              "dial"  *</code></li>
 
<li>Edit <code>/etc/ppp/pap-secrets</code> and append the username and password (quotes included)<br /> <code>dial    *              "dial"  *</code></li>
 
<li>Enable packet forwarding for IP4 by editing <code>/etc/sysctl.conf</code><br /><code>net.ipv4.ip_forward=1</code><li>
 
<li>Enable packet forwarding for IP4 by editing <code>/etc/sysctl.conf</code><br /><code>net.ipv4.ip_forward=1</code><li>
 +
<li>
 +
 +
Last step for the dial-up server is to configure the firewall to allow forwarding of traffic from PPP out onto the network (and off to the internet)<br />
 +
<ol>
 +
<li>On linux distros with iptables you need to add a line to <code>/etc/rc.local</code> to enable masquerading. If your ethernet interface is named eth0 you would add this line: <code>iptables -t nat -A POSTROUTING -s 192.168.32.0/24 -o eth0  -j MASQUERADE</code>
 +
</li>
 +
<li>
 +
On modern Ubuntu installs ufw is used instead of iptables so the procedure is a bit different. Follow this guide but you can omit <code>-o eth0</code> and use <code>-s 192.168.32.0/24</code> <br /> https://help.ubuntu.com/lts/serverguide/firewall.html.en#ip-masquerading
 +
</li>
 
</ol>
 
</ol>
 +
</li>
 +
</ol>
 +
 +
 +
== Debugging ==
 +
Choice of USB to RS232 adapter seems to be crucial and very finicky. The USB adapter Ive been using on a raspberry pi, which worked perfectly would not work a properly on a x86_64 debian system.
 +
To debug modem communication and baud rate use either minicom (or your editor of choice!) to open a session over serial. Sending the command AT followed by enter should result in your modem replying OK
 +
 +
I actually ran into a bug in Debian 9.5 with my ch341 based usb to serial where setting the baud rate was not working. (Seems to be this: https://bugzilla.redhat.com/show_bug.cgi?id=1235715)

Revision as of 05:40, 7 February 2019

Becoming your own dial-up ISP in 2019

Required hardware:

  • A hardware modem (not a software modem/winmodem, must be the real deal)
  • A computer to install linux on to talk to the a modem (Can be anything that a modern linux distribution will run on. Raspberry Pi, Pi clone, x86 machine, etc)
  • A client device (windows 9x PC for example) with a modem
  • Some form of PSTN to connect the two modems


The exact hardware I’ve used

  • Generic x86_64 PC running Ubuntu Server 18.04
  • Matrix “MX Modem” (more on this later)
  • USB to RS232 serial adapter (DE-9) to connect to the modem (Must support hardware flow control)
  • DE-9 to DB-25 serial adapter
  • Linksys PAP2T analog telephone adapter (ATA)
  • x86 based Windows 95 PC with a US Robotics Sportster 28800 ISA modem


Software used

  • Ubuntu server 18.04
  • PPP
  • getty
  • Asterisk


Preparing the dial-in-server

  1. Install Debian/Ubuntu/Raspbian per the usual methods (not covered here)
  2. Update to latest packages and reboot if required
  3. sudo apt-get update
    sudo apt-get upgrade
    sudo reboot
  4. Connect USB to RS232 adaptor and confirm it shows up as /dev/ttyUSBXXX (ls /dev/ to check) In my case it presents as /dev/ttyUSB0
    My serial adaptor is a "ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adaptor"

    Full lsusb output:
    # sudo lsusb -v
    Bus 004 Device 003: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
    Device Descriptor:
      bLength                18
      bDescriptorType         1
      bcdUSB               1.10
      bDeviceClass          255 Vendor Specific Class
      bDeviceSubClass         0 
      bDeviceProtocol         0 
      bMaxPacketSize0         8
      idVendor           0x1a86 QinHeng Electronics
      idProduct          0x7523 HL-340 USB-Serial adapter
      bcdDevice            2.54
      iManufacturer           0 
      iProduct                2 USB2.0-Ser!
      iSerial                 0 
      bNumConfigurations      1
      Configuration Descriptor:
        bLength                 9
        bDescriptorType         2
        wTotalLength           39
        bNumInterfaces          1
        bConfigurationValue     1
        iConfiguration          0 
        bmAttributes         0x80
          (Bus Powered)
        MaxPower               96mA
        Interface Descriptor:
          bLength                 9
          bDescriptorType         4
          bInterfaceNumber        0
          bAlternateSetting       0
          bNumEndpoints           3
          bInterfaceClass       255 Vendor Specific Class
          bInterfaceSubClass      1 
          bInterfaceProtocol      2 
          iInterface              0 
          Endpoint Descriptor:
            bLength                 7
            bDescriptorType         5
            bEndpointAddress     0x82  EP 2 IN
            bmAttributes            2
              Transfer Type            Bulk
              Synch Type               None
              Usage Type               Data
            wMaxPacketSize     0x0020  1x 32 bytes
            bInterval               0
          Endpoint Descriptor:
            bLength                 7
            bDescriptorType         5
            bEndpointAddress     0x02  EP 2 OUT
            bmAttributes            2
              Transfer Type            Bulk
              Synch Type               None
              Usage Type               Data
            wMaxPacketSize     0x0020  1x 32 bytes
            bInterval               0
          Endpoint Descriptor:
            bLength                 7
            bDescriptorType         5
            bEndpointAddress     0x81  EP 1 IN
            bmAttributes            3
              Transfer Type            Interrupt
              Synch Type               None
              Usage Type               Data
            wMaxPacketSize     0x0008  1x 8 bytes
            bInterval               1
    Device Status:     0x0000
      (Bus Powered)
    
  5. Install ppp (and getty if your distro doesn’t have it by default)
    sudo apt-get install ppp mgetty
  6. Many of the old guides were written when inittab was still around but its 2019 and systemd has taken over.
    We need to create a systemd service for mgetty so edit /lib/systemd/system/mgetty.service with your text editor of choice with elevated privileges (sudo)
    [Unit]
    Description=External Modem
    Documentation=man:mgetty(8)
    Requires=systemd-udev-settle.service
    After=systemd-udev-settle.service
    
    [Service]
    Type=simple
    ExecStart=/sbin/mgetty /dev/ttyUSB0
    Restart=always
    PIDFile=/var/run/mgetty.pid.ttyUSB0
    
    [Install]
    WantedBy=multi-user.target
    
  7. Configure mgetty by editing /etc/mgetty/mgetty.config with your text editor of choice with elevated privileges (sudo)
    Comment out everything except the debug level and append the section for configuring the serial device
    debug 9
    
    port ttyUSB0
     port-owner root
     port-group dialout
     port-mode 0660
     data-only yes
     ignore-carrier no
     toggle-dtr yes
     toggle-dtr-waittime 500
     rings 2
     #autobauding yes
     speed 9600
    
  8. Enable the mgetty service so it starts on boot
    sudo systemctl enable mgetty.service
  9. Start mgetty
    sudo systemctl start mgetty.service
  10. Configure ppp by editing /etc/ppp/options
    Like above comment out everything except these settings
    # Define the DNS server for the client to use
    ms-dns 8.8.8.8
    # async character map should be 0
    asyncmap 0
    # Require authentication
    auth
    # Use hardware flow control
    crtscts
    # We want exclusive access to the modem device
    lock
    # Show pap passwords in log files to help with debugging
    show-password
    # Require the client to authenticate with pap
    +pap
    # If you are having trouble with auth enable debugging
    debug
    # Heartbeat for control messages, used to determine if the client connection has dropped
    lcp-echo-interval 30
    lcp-echo-failure 4
    # Cache the client mac address in the arp system table
    proxyarp
    # Disable the IPXCP and IPX protocols.
    noipx
    
  11. Create a device option file by editing /etc/ppp/options.ttyUSB0
    local
    lock
    nocrtscts
    192.168.32.1:192.168.32.105
    netmask 255.255.255.0
    #debug
    noauth
    proxyarp
    lcp-echo-failure 60
    
  12. Create the user used for PAP authentication
    sudo useradd -G dialout,dip,users -m -g users -s /usr/sbin/pppd dial
  13. Change the password (I set it to dial)
    sudo passwd dial
  14. Edit /etc/ppp/pap-secrets and append the username and password (quotes included)
    dial * "dial" *
  15. Enable packet forwarding for IP4 by editing /etc/sysctl.conf
    net.ipv4.ip_forward=1
  16. Last step for the dial-up server is to configure the firewall to allow forwarding of traffic from PPP out onto the network (and off to the internet)
    1. On linux distros with iptables you need to add a line to /etc/rc.local to enable masquerading. If your ethernet interface is named eth0 you would add this line: iptables -t nat -A POSTROUTING -s 192.168.32.0/24 -o eth0 -j MASQUERADE
    2. On modern Ubuntu installs ufw is used instead of iptables so the procedure is a bit different. Follow this guide but you can omit -o eth0 and use -s 192.168.32.0/24
      https://help.ubuntu.com/lts/serverguide/firewall.html.en#ip-masquerading


Debugging

Choice of USB to RS232 adapter seems to be crucial and very finicky. The USB adapter Ive been using on a raspberry pi, which worked perfectly would not work a properly on a x86_64 debian system. To debug modem communication and baud rate use either minicom (or your editor of choice!) to open a session over serial. Sending the command AT followed by enter should result in your modem replying OK

I actually ran into a bug in Debian 9.5 with my ch341 based usb to serial where setting the baud rate was not working. (Seems to be this: https://bugzilla.redhat.com/show_bug.cgi?id=1235715)