ping fails but dig / nslookup works?

I’ve now run into two scenarios where this happened. The most recent was after I had to kill a vpnc process (used to connect to a cisco VPN).

It looks like this:

[james@workstation ~]$  ping google.com
ping: unknown host google.com

[james@workstation ~]$  dig google.com +short
72.14.204.147
72.14.204.99
72.14.204.103
72.14.204.104

What ended up happening was that the VPN was configured to tunnel all traffic through it, so when it re-wrote the /etc/resolv.conf file, it didn’t append the VPN nameservers to the nameservers provided to us by our DHCP lease, but completely overwrote them. I’m assuming that when you closed the VPN it would replace the resolv.conf file with the one containing the non-VPN nameservers but since I killed it, it was not restored.

Anyway, the fix was easy but finding it out was annoying.

All you have to do is release and renew your DHCP lease.

You could try:

dhclient -r; dhclient

… but I was on an SSH connection and I didn’t quite trust the second command to be run after I lost the connection when the lease was released (this seems like a silly fear but whatever).

Instead I wrote a bash script and put it in a file:

#!/bin/bash
#refreshlease.sh
IFACE="eth0"

dhclient -r ${IFACE}
dhclient ${IFACE}

… and ran that over the SSH connection. The connection seemed to get dropped for a few seconds but then came back up. Checking /etc/resolv.conf showed that my original nameservers were, in fact, back and I was able to resolve DNS queries:

[james@workstation ~]$  ping google.com
PING google.com (64.233.169.105) 56(84) bytes of data.
64 bytes from yo-in-f105.1e100.net (64.233.169.105): icmp_seq=1 ttl=238 time=31.1 ms
Leave the first comment

Quick Bash Trick: Looping through output lines

Lets say you want to add line numbers to a text file. For example, you want to see this file:

The quick brown fox
jumps over the
lazy dog

… displayed on your screen list this:

1  The quick brown fox
2  jumps over the
3  lazy dog

Of course, you could use cat -n if you’re using cat and want line numbers, but if you want to, say, add a 4 space indent to the output of iwconfig, the following technique will work.

First, we run the program / script and capture the output:

output=$(iwconfig 2>/dev/null)

Here we’re running iwconfig in a subshell and capturing the output. In this case, I’m redirecting stderr to /dev/null, otherwise iwconfig returns lines like lo no wireless extensions. up through the subshell to the shell thats calling the bash script. I don’t want this so I’m throwing it out.

Next, we loop through the output using a for loop:

for LINE in ${output} ; do

    echo ${LINE}

done

Running this will not get us the output we’re expecting, it will return each space-separated word/phrase on it’s own line. If we are still talking about the pangram above, we would see:

The
quick
brown
fox
jumps
over
the
lazy
dog

The problem is, the IFS (Internal Field Separator) contains the space character.

(Quick Aside)
To see what the IFS is, type:

echo -n "$IFS" | hexdump

My IFS contains 0×09, 0×20, 0x0a (tab, space and newline respectively).
(End Aside)

We can change the $IFS in our script (to only contain the newline character) which lets us iterate through the output where separated by newlines.

First, we save the original IFS and define the newline IFS:

OIFS="${IFS}"
NIFS=$'\n'

Next we set the IFS to our newline IFS:

IFS="${NIFS}"

Then, we loop through the output (in the loop we reset the IFS incase we expect it to include the space, etc. and then set it to newline IFS before our next iteration)

for LINE in ${output} ; do
    IFS="${OIFS}"

    echo "---- ${LINE}"

    IFS="${NIFS}"
done

Lastly, we reset the IFS:

IFS="${OIFS}"

The final code looks like this:

        output=$(iwconfig 2>/dev/null)

        OIFS="${IFS}"
        NIFS=$'\n'

        IFS="${NIFS}"

        for LINE in ${output} ; do
            IFS="${OIFS}"

            echo "---- ${LINE}"

            IFS="${NIFS}"
        done
        IFS="${OIFS}"

… and we get what we had hoped:

---- The quick brown fox
---- jumps over the
---- lazy dog

In closing, it should be noted that I’ve done this a few different ways (including splitting the output with awk / sed) but I like the simplicity of this method. I may try to find the other methods and write them up to if I get some time.

P.S. If you ever need to reset your IFS but don’t want to close the terminal, type this:

IFS=$'\n\t '
2 comments so far, add yours

iGoogle Minimalized

I hated how much space the Google header took up at the top of the page. I searched for themes but none seemed to address the issue. I then looked into developing my own theme through their theme API and it turns out the reason none of the themes address the large header is because Google doesn’t give the developer the option to control that.

All you can really control is colors, add a few custom images and select between icon sets, but nothing having to do with sizing or positioning.

My next step was to examine the DOM and whip up a GreaseMonkey Script that shrunk it. Having some experience with it, I made use of a few jQuery features in the script.

Before:

Before

Before

After:

After

After

Enjoy!

Direct Download

// ==UserScript==
// @name           Minimalize iGoogle Theme
// @namespace      http://www.edwards-research.com
// @description    Minimalize iGoogle Theme
// @author         by James Edwards
// @include        http://www.google.com/
// @include        http://www.google.com/ig
// @require        http://code.jquery.com/jquery-latest.min.js
// ==/UserScript==

// Written by James Edwards
//		Feel free to use this script in any way you like, commercial or otherwise.
//		Attribution is optional but encouraged.
//
// jQuery Integration from: Greasespot
//		http://wiki.greasespot.net/Code_snippets#Use_jQuery_in_a_GreaseMonkey_script
(function() {
	//<div id="nhdrwrap">
		$("div#nhdrwrap").css("padding","0px");
		$("div#nhdrwrap").css("margin","0px");
		$("div#nhdrwrap").css("height","100px");
	//<div id="nhdrwrapinner">
		$("div#nhdrwrapinner").css("background-image","none");
		$("div#nhdrwrapinner").css("height","100px");
		$("div#nhdrwrapinner").css("margin-top","-20px");
	//<div id="regular_logo">
		$("div#regular_logo").hide();
	//<p class="gseaopt">
		$("p.gseaopt").hide();
	//<div class="personalize_link">
		$("div.personalize_link").hide();
	//<div id="header_promo_wrapper">
		$("div.header_promo_wrapper").hide();
	//<div id="promo" class="sandbox_msg" style="margin-top:-20px;"
		$("div.sandbox_msg").hide();
	//<div class="gradient">
		$("div.gradient").hide();

}());
Leave the first comment

Color Schemes for Eclipse CDT – Part 4

I’m proud to announce the alpha release of the Eclipse Theme Generator (available here). This site allows you to design a color-scheme in real-time and see how it looks. After you are happy with your theme, you can proceed to export the settings into the appropriate files.

Eclipse CDT Theme Generator

Some things to note:

  • This is just an alpha release, seriously, there are many shortcomings and I’m sure a few bugs.  If you come across one, please leave a comment here detailing it.  If there is a feature you’d like to see, please feel free to comment here.  If I get enough of a response, I’ll setup a trac site for the project.
  • The preview only shows you about 10 different (the most common in my opinion) settings.  There are options to customize many more colors, and changing those settings will encode the appropriate lines in the config. files, but you will not be able to see what they look like until you load it into Eclipse.
  • I will eventually add options to change font style (bold, italic, underlining) but as of now there is no support for that and you must go in and manually change the settings afterwards (see colorsets for more information on where in the Eclipse UI you can change certain settings).
  • As of now the generator generates files with a lot of debug messages (messages starting with #NOTE or #WARN).  This is debugging information and doesn’t necessarily mean there will be a problem with your files once you import them.
  • If you somehow wind up with a theme that you don’t like or looks broken, you can always exit eclipse, delete the three files generated and restart eclipse at which point it will revert to the standard styles.
 

Finally, the default theme is based on Zenburn (as defined here).  Eventually, I’d like the generator to allow you to start with any number of predefined themes so you can tweak them as you desire, but that functionality is not built in yet — if its something you’d like to see, please consider adding a comment saying so.

Enjoy.

11 comments so far, add yours

Gigabit LAN Upgrade

Not much time to post, so I’ll post the quick bandwidth test we did between two machines before and after the LAN upgrade:

Gigabit-Performance-Table-Fixed

Some notes:

  • For a bandwidth tester we used iperf, a linux script that has been ported to windows via a cygwyn build.
    • For Linux we just ran “yum install iperf”
    • For Windows we googled “iperf windows”, but here is one binary from UCF.
  • The real path just explains the connection between the two units.
  • The window size was automatically determined by iperf.
  • The 10 second test duration is iperf’s default.

And the same data graphically:

Gigabit-Performance-Chart

As you can see, there is considerable bandwidth improvement, even for the integrated NIC (and the PCI NIC is more than twice as fast as that!)

Leave the first comment

How To: Speed up X Tunneling over SSH

I use PuTTY (actually, I use PuTTY tray) and XWin Server to run Linux GUI applications in Windows.  Basically, I have a headless Linux server running and I connect to it via SSH.  While 90% of the things I do on it are command-line based, I’ve yet to find a real good strategy for developing true linux C/C++ applications from a Windows machine, so I end up running Eclipse on the headless box with the windows tunneled to my Windows system.  (I say true because I know I could use something like MinGW or Cygwin and get 99% of the functionality, but I’m picky about that last 1%).  Also, I know there is a really interesting project underway in the Eclipse community to get CDT to build and debug remotely (Remote Development Tools), but I ran into all kinds of problems getting it to work and it really wasn’t worth the time I was spending on it.  Further, X tunneling over SSH worked great.

I wasn’t satisfied though.

My LAN’s throughput chokepoint was my router, limiting connections to 100Mbps so I went ahead and ordered a Gigabit switch and upgraded my cabling (it was pretty shoddy) and one of my NICs.  Before they come in though, I decided to explore some ways to improve tunneling without hardware changes.

The first thing I looked into was changing SSH cipers.

You can look at the available ciphers in PuTTY by going into the configuration window, and under Connection, clicking SSH.  You should see something like this:

SSH-Cipher-Putty-SSH

You can change the the order that these ciphers are considered simply by clicking Up or Down and rearranging them.  I like to put the one I want at the top, then immediately following it with the “–warn below here–” tag, so I know definitively whether I’m getting my #1 choice.

But how do I know which ciper to choose?

Thats a good question, and I didn’t know either.  I did some extremely quick googling and I didn’t get a very definitive answer in the 2 or 3 pages I landed on, but I did find a nice command to run a benchmark on your local system so you can find out for yourself.  The command was:

openssl speed -engine padlock -evp *ciper* 

Where *ciper* is replaced by the name of the cipher you wish to test.  Executing this command starts an OpenSSL script which runs through the algorithm on locally on your computer, measuring the number of computations it can perform per second.

I extended this command with a simple tweak that allowed me to loop through the script using mulitple different ciphers:

for ENC in aes-256-cbc bf bf-ecb rc4 rc4-40 bf-cfb bf-ofb des3 des ; do openssl speed -engine padlock -evp ${ENC} ; done

After executing this, I walked away for a little (probably takes less than 5 mintutes but I didn’t want to introduce any more variability by messing around during the benchmark) and when I cameback it has maybe 150 lines of output, about 15 for each ciper.

Being the quantitative dude that I am, I immediately threw the data into Excel and plotted the processing throughput (in KBps and given on the last line of each iteration) vs block size (given on the second to last line).

The results were really surprising.  Here’s the table I compiled:

SSH-Cipher-Table

Where the highlighted cells indicate maximum throughput for each column or blocksize.  Its pretty apparent from this that RC4 really flys, but the table above doesn’t do the improvement justice.  Lets look at the data plotted:

Note: The label on the vertical axis incorrectly states the units as KBps when they are, in fact, MBps.

(click for full-size)

(click for full-size)

Wow, that is really a tremendous difference between the two RC4 ciphers and the rest, more often than not doubling the throughput of their alternatives.

So with such a huge difference in performance, certainly the RC4 cipher is the default cipher in PuTTY, right?  Actually, no.  At least in my vanilla PuTTY installations, RC4 (AKA Arcfour in PuTTY) is fairly low on the list, only preferred over DES.

I’m not a cryptographer, and I’m not well versed on the differences between the ciphers certainly not well enough to give any informed opinion on which cipher to choose from a security point of view, but from a sheer speed point of view, it would seem that RC4 would preferred.

Now our network is secured from the WAN side by a firewall on our router which we are trusting to prevent unauthorized access to the LAN side, so for us, encrypting SSH sessions that strictly live on the LAN side with a possibly sub-par cipher was acceptable if it provided the latency improvement that it looked like it would.  Your circumstances may differ and I urge you to consider all of them before you go changing settings.

Given that you’ve considered them, and you’re comfortable, lets go ahead and change the ciper priorities and see if we get any improvement.

Simply by clicking the cipher we want to move, then the Up / Down buttons, we were able to configure our priorities to this:

SSH-Cipher-Putty-SSH-Modified

The idea here being that if, for some reason, we can’t establish a link with RC4, we’ll be notified.  We could then go back into the settings and move the “–warn below here–” line down a line and try again, hoping to connect with the Blowfish ciper, the second quickest cipher or otherwise receive a warning.

Results

Unfortunately, I don’t have any quantitative data to show the latency improvement, although I suppose you could demonstrate a bandwidth / throughput increase by doing a file transfer, however it is abundantly clear that there was, in fact, a huge latency improvement.  Things that caused annoying lag (eg clicking on the scrollbar to scroll quickly) showed a noticeable improvement.

As it is, without real data to show the improvement, you are left to experiment with the settings yourself, and, given you feel comfortable, I strongly encourage doing so — as it really seems to make a difference.

I’ll be sure to check back here when we receive the Gigabit hardware and present a before and after look at our LAN transfer speeds.

One comment so far, add another

Color Schemes for Eclipse CDT – Part 3

As requested, I’ll post some of the theme’s I’ve done.  Once I finalize the configuration utility, I should be able to pump out a ton of these, but until then… here are my two favorite right now.

5 comments so far, add yours

How To: 64-bit Eclipse + 64-bit Windows 7

WARNING: There are tutorials out there that tell you to do weird things like rename eclipse.exe to eclipse1.exe or change the eclipse.ini configuration file — none of these steps are necessary and from what I can tell, even useful.

It’s really simple.

Download 64-bit JRE: here / possibly outdated direct link

Install the JRE.

Download 64-bit Eclipse: here / possibly outdated direct link

Extract Eclipse.

You’re good to go.

Note: If you get an error saying it can’t find the JVM in the path it searched:

  • Click the windows button, type “environment variables” (you might get away with just “env”) then click the link that says: “Edit the system environment variables” — the System Properties dialog comes up.
  • Click Environment Variables…
  • On the bottom half of the Environment Variables dialog, scroll for the PATH variable.
  • Click the PATH variable and then click Edit…
  • At the end of the line, add a semicolon and then the path to your JVM (javaw.exe) — for reference mine was: C:\Program Files\Java\jre6\bin
3 comments so far, add yours

Color Schemes for Eclipse CDT – Part 2

The next step of our journey involved trying to recreate one of the themes we found in through Eclipse’s IDE Preferences.  Believe me, this is no easy task.  There are like 4 different places that colors, highlights and fonts are stored.

The most are stored in:  Window, Preferences, C/C++, Editor, Syntax Coloring

There you will find options to color built-in types, typedefs, pre-processor directives, strings, etc.  All the things you would expect to find.  A nice feature they have for many of the types is the ability to disable syntax coloring.  There were a few that I just chose to disable or keep disabled because it was getting too cluttered.  I still think its too cluttered actually.  Judge for yourself:

Standard Theme / Coloring

ER-Eclipse-NoTheme

My Twilight-ish Theme / Coloring

ER-Eclipse-MyWombat

Following the trend of having settings all over the place, these customizations are contained in four files:

  • …/workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.cdt.ui.prefs
  • …/workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.ui.prefs (weird, I know).
  • …/workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.editors.prefs
  • …/workspace/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.ui.prefs

The large majority of the settings are in the cdt.ui.prefs file:

semanticHighlighting.typedef.color=117,135,166
semanticHighlighting.enum.color=143,157,106
c_type=117,135,166
semanticHighlighting.functionDeclaration.color=155,133,157
useQuickDiffPrefPage=true
c_string=169,188,135
c_single_line_comment=79,148,205
useAnnotationsPrefPage=true
semanticHighlighting.macroSubstitution.color=117,135,166
semanticHighlighting.method.enabled=true
semanticHighlighting.functionDeclaration.bold=false
semanticHighlighting.macroSubstitution.italic=true
c_comment_task_tag=79,148,205
spelling_locale_initialized=true
semanticHighlighting.globalVariable.enabled=true
semanticHighlighting.method.bold=true
c_comment_task_tag_italic=true
c_braces=205,168,105
c_numbers=207,106,76
semanticHighlighting.class.color=233,192,98
semanticHighlighting.enumerator.color=143,157,106
semanticHighlighting.field.enabled=false
semanticHighlighting.macroSubstitution.enabled=true
c_keyword=233,192,98
semanticHighlighting.function.color=155,133,157
pp_default=143,157,106
c_multi_line_comment=79,148,205
semanticHighlighting.externalSDK.enabled=false
semanticHighlighting.function.enabled=true
semanticHighlighting.method.color=155,133,157
eclipse.preferences.version=1
semanticHighlighting.methodDeclaration.color=155,133,157
semanticHighlighting.problem.color=224,125,87
pp_header=143,157,106
semanticHighlighting.staticMethod.enabled=false
semanticHighlighting.globalVariable.color=207,106,76
semanticHighlighting.templateParameter.enabled=false
c_default=248,248,248
c_multi_line_comment_italic=true
semanticHighlighting.function.bold=false
c_operators=173,216,230
c_single_line_comment_italic=true
semanticHighlighting.staticField.color=155,133,157
pp_directive=233,192,98

The other places to look for coloring options are:

  • Window, Preferences, General, Editors, Text Editors, Appearance Color Options
  • Window, Preferences, General, Editors, Text Editors, Annotations, Occurences

I’m going to mess around and create one more theme by hand — then try to figure out the best way to implement a solution that will be full-featured and allow for easy transition between themes.  Maybe a webapplet where you can design the theme (or customize a pre-existing one) and then download it?  Who knows…

2 comments so far, add yours

Color Schemes for Eclipse CDT – Part 1

I’ve looked all over for color schemes / color themes for Eclipse CDT and have found almost nothing. I would love an Eclipse plugin that would let me import new style sheets and export any custom color settings. Unfortunately, it doesn’t look like thats out there yet. Maybe that will be something I pick up when I’m bored — man you know you’re busy when you look forward to being bored.

Anyway — the goal of this post / series of posts is to get some kind of solution that’s manageable and relatively painless. Instead of going the full plugin route (yet), I’m going to whip up some shell scripts that will hopefully make my life easier.

I should point out that color schemes are available for Eclipse Languages (eg Java and PHP) but not CDT (schemes are language-specific because of the syntax intricacies).

So lets look at a color scheme file — one site says that they are located:

[workspace]\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.jdt.ui.prefs
[workspace]\.metadata\.plugins\org.eclipse.core.runtime\.settings\org.eclipse.ui.editors.prefs

… so lets check it out.

org.eclipse.jdt.ui.prefs

#Sat Jun 6 19:04:05 EDT 2009
useQuickDiffPrefPage=true
proposalOrderMigrated=true
tabWidthPropagated=true
content_assist_proposals_background=255,255,255
org.eclipse.jdt.ui.javadoclocations.migrated=true
useAnnotationsPrefPage=true
org.eclipse.jface.textfont=1|Monospace|10.0|0|GTK|1|;
org.eclipse.jdt.internal.ui.navigator.layout=2
org.eclipse.jdt.ui.editor.tab.width=
org.eclipse.jdt.ui.formatterprofiles.version=11
spelling_locale_initialized=true
eclipse.preferences.version=1
content_assist_proposals_foreground=0,0,0
fontPropagated=true

org.eclipse.ui.editors.prefs
(I didn’t have this file, at least not there)

So here’s the plan, I’m going to track down where these files are (its possible they aren’t even created unless you deviate from the defaults), figure out the format, and then figure out the best way to set up theme packages.

In the meantime, I’m going to leave you with some links of popular themes I hope to get setup.

Stay tuned.

One comment so far, add another