[태그:] 모뎀

  • 전화접속 서버 만들기

    이번에는 전화로 인터넷에 접속하는 서버를 만들 것이다.

    우선 가상머신에 우분투 서버를 깔아주고 USB모뎀을 연결해 주었다.

    다음 명령어를 입력하여 mgetty와 ppp를 깔아준다.

    sudo apt update
    sudo apt upgrade
    sudo apt install mgetty ppp

    이제 mgetty가 자동으로 실행 되도록 서비스를 등록해 줄 것이다.

    /lib/systemd/system/mgetty.service 파일을 만들어 준 후 다음 내용을 채워 넣는다.

    [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/ttyACM0
    Restart=always
    PIDFile=/var/run/mgetty.pid.ttyACM0
    
    [Install]
    WantedBy=multi-user.target

    그리고 이제 /etc/mgetty/mgetty.config 파일을 열고 맨 아래에 다음 내용을 채워 넣는다.

    debug 9
    
    port ttyACM0
     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 57600

    그리고 아래 명령어를 실행해서 부팅시 켜지도록 해 준다.

    sudo systemctl enable mgetty.service

    재부팅 하고나서 서버로 전화를 걸면 터미널에 접속할 수 있다.

    터미널 접속 영상

    이제 ppp를 설정해 줄 것이다 /etc/ppp/options 파일일에서 아래 부분과 같이 주석을 해제하고 수정해 준다

    # 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
    # Require the client to authenticate with pap
    +pap
    # 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

    이제 /etc/ppp/options.ttyACM0 를 아래 내용으로 생성해 준다

    local
    lock
    nocrtscts
    192.168.32.1:192.168.32.105
    netmask 255.255.255.0
    noauth
    proxyarp
    lcp-echo-failure 60

    이제 ppp계정을 만들 것이다. 계정을 만들고 비밀번호를 설정해 주

    sudo useradd -G dialout,dip,users -m -g users -s /usr/sbin/pppd ppp
    sudo passwd ppp

    /etc/ppp/pap-secrets 파일의 맨 아랫부분에 아래와 같이 아까 만든 아이디와 비밀번호를 추가 한다.

    아이디 * "비밀번호" *

    이제 ppp에 사용되는 ip가 외부에 접근할 수 있도록 설정을 해야 한다.

    /etc/systemd/system/ppp-ready.service 파일을 만들고 아래 내용을 넣는다.

    [Unit]
    After=network.target
    
    [Service]
    ExecStart=/usr/local/bin/ppp-ready.sh
    
    [Install]
    WantedBy=default.target

    그리고 /usr/local/bin/ppp-ready.sh 파일을 만들고 아래 내용을 넣는다.

    #!/bin/bash
    iptables -t nat -A POSTROUTING -s 192.168.32.0/24 -o enp0s3 -j MASQUERADE

    아래 명령어를 입력 해 파일의 권한을 수정해 준다

    sudo chmod 744 /usr/local/bin/ppp-ready.sh
    sudo chmod 644 /etc/systemd/system/ppp-ready.service

    마지막으로 /etc/sysctl.conf 파일에서 아래 부분을 주석 해제 한다.

    net.ipv4.ip_forward=1

    이제 다 끝났다 시스템을 껐다가 키면 이제 전화 접속을 할 준비가 됐다.

    아래는 전화 접속으로 Google에 접속하는 영상이다.

    인터넷 연결 영상

    참조
    Dial up server – Doge Microsystems
    How to run script on startup on Ubuntu 22.04 Jammy Jellyfish Server/Desktop – Linux Tutorials – Learn Linux Configuration