connect to internet through 3g dongle in ubuntu server

Solution 1:

There is an answer here on how to connect via mobile broadband using the network manager through the terminal: How to enable/disable mobile broadband from terminal?.

Network manager doesn't come with Ubuntu server as most server installs just have static IPs set on startup by configuration in /etc/networking/interfaces so you'll have to install it.

However, I am questioning why you would do this. I assume you are installing Ubuntu server to actually run a server that can be accessed from the web. Since most if not all mobile broadband providers run carrier-grade NAT, you will not have a publicly routable address under your control and thus no one will be able to access your server.

Solution 2:

http://www.draisberghof.de/usb_modeswitch/bb/viewtopic.php?f=4&t=1114

  1. Create a new file named "12d1:1526" in the folder "/etc/usb_modeswitch.d" and fill it with this content:

    # Vodafone K3772 (Huawei)
    
    TargetVendor=  0x19d2
    #TargetProduct= not known yet
    
    MessageContent="55534243123456780000000000000011062000000100000000000000000000"
    
  2. Duplicate one of the existing Huawei lines in "/lib/udev/rules.d/40-usb_modeswitch.rules" and edit the new line to reflect the product ID of your device (... ATTRS{idProduct}=="1526" ...). It's easy, just look at the other lines.

  3. Now, plug your modem in and wait at least 10 seconds. After this run the lsusb command in a terminal program. There should be a device ID starting with "12d1" but most likely different than "12d1:1526". The changed part of the ID (after the colon) is your new "TargetProduct" value (prepended by "0x"). Edit your config file accordingly, removing the comment sign (hash) at the start of the TargetProduct line.

  4. Unplug the modem and plug again. Wait ... (Huawei modems need up to 10 seconds for the mode switch.) Run dmesg in a terminal program and you should see something like "GSM modem (1-port) converter now attached to ttyUSBx". This means that your modem is ready to use.