🕹ī¸ Do Something Great! 😄

Tag: ifconfig

  • Uploading my current IP address so I can find my Pi

    For some reason my autossh job is failing to set up the reverse tunnel so I can find and connect to my Pi when the Pi is roaming. Until I figure out why that is happening, I wrote this bash script which will upload the wifi interface’s current IP address to a remote server.

    1
    2
    3
    4
    #!/bin/bash
    
    echo `ifconfig wlan0 | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'` | \
        ssh [email protected] "cat > ~/myip.txt"
    

    I already have ssh passwordless logins in set up because of autossh. If you don’t have that set up, then you’ll need to do that first or this won’t work. I then add a cron job to run this script every minute.

  • The loopback interface is very important

    This is more of a note to remind me how to fix it next time, but it could come
    in handy for others in the same situation.

    I restarted my virtual private server this morning, and after it came back up I
    noticed none of the websites would load. The server runs
    Varnish as a front end to all the websites,
    and all it was doing was throwing up 503 errors and guru meditations. This means
    that varnish can’t connect to any web server. The websites on the host are
    served by nginx and apache. I double checked that they were running and that
    they were on their correct ports with netstat -tulpn:

    tcp        0      0 0.0.0.0:8008            0.0.0.0:*               LISTEN      391/apache2
    tcp        0      0 0.0.0.0:88              0.0.0.0:*               LISTEN      12365/nginx.conf
    

    Ok, everything is running, why won’t it work!! Next is to try to telnet to the
    servers:

    telnet localhost 8008
    

    That’s odd, it never connects. Let me try it from my computer (IP address
    obscured. Why? I don’t know, it seems like a good idea :-).

    telnet 75.255.255.255 8008
    

    It connects right away. So for some reason, the server can’t connect to other
    services on itself, even localhost. After some searching I came across a post
    that mentions that sometimes the loopback interface doesn’t come up. I check:

    root@vps:~# ifconfig
    venet0    Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
              inet addr:127.0.0.2  P-t-P:127.0.0.2  Bcast:0.0.0.0  Mask:255.255.255.255
              UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1
              RX packets:32802 errors:0 dropped:0 overruns:0 frame:0
              TX packets:35269 errors:0 dropped:52 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:10716892 (10.7 MB)  TX bytes:25360227 (25.3 MB)
    
    venet0:0  Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
              inet addr:75.255.255.255  P-t-P:75.127.3.166  Bcast:0.0.0.0  Mask:255.255.255.255
              UP BROADCAST POINTOPOINT RUNNING NOARP  MTU:1500  Metric:1
    

    I’ll be a monkey’s uncle, the loopback interface isn’t up! A quick sudo
    ifconfig lo up
    and I am back in business!