Posts

Showing posts with the label tips

Discover Switch Port Using tcpdump and wireshark

Discover the Switch Port to which the Server is Connected A previous article, Advanced Linux Networking Tools , covered the basic usage of tcpdump and tshark to discover switch ports on a Cisco switch, but there are times a system may be connected to a different brand, or using a different protocol.  Also, wireshark is not always installed, so relying on tshark is not always the most convenient way to get the required info. By default, Cisco uses a proprietary method of communication between switches and routers called Cisco Discovery Protocol (CDP).  There is another protocol called Link Layer Discovery Protocol (LLDP), which used by other brands, so it is useful to list other options. Find switch information First, use ifconfig to find the interface names.  Then, use tcpdump to listen for packets.  Optional:  write the packet capture output to a .cap file, and use tshark to read the output. Cisco Discovery Protocol (CDP) YOUR_INTERFACE=eth0 ...

Bash One-Liners for Ping

Image
Here are a few notes to add to the previous article on ping. This time, we look at some bash one-liner tips and tricks. Combine multiple commands Return Values Ping Multiple Hosts Using Bash Nmap and Fping Ping, and Command Line Variables Start from the beginning. We want to see what happens when attempting to ping a host that resolves an IP address from DNS, but is not reachable from our network at the moment. This is to show how we might build a simple monitoring tool from scratch, and also to see what kind of fun we can have with the command line. To ping a host only one time use the count option, which in Windows is -n, and in Linux is -c. Windows C:\>set host=google.com C:\>ping -n 1 %host% Pinging google.com [216.58.219.46] with 32 bytes of data: Request timed out. Ping statistics for 216.58.219.46: Packets: Sent = 1, Received = 0, Lost = 1 (100% loss), Bash: Linux, Mac, Unix Note that in bash, we don't use the set command to assign a varia...

Git Quick Start

When attempting to learn new tools, such as git, or vim, it is easy to get lost in all the features.  Here is a quick start guide that focuses on the essentials for a single user to get started with a local git repo.  Working with a team, and advanced features can be added later. Git Quick Start Commands Git Core Commands git init git add . git commit -m “initial commit” Supporting Commands git status git log Remote Repository Commands git clone [url] git pull git push Git Notes on github goes into more detail https://github.com/systemnotes/gitnotes

Get a List of rpms for a Specific Program or Version

Image
Systems that use rpm as the package manager can often be managed by using yum, but sometimes a simple rpm command can quickly give the required information. The RPM Package Manager has a huge number of options, but most commonly only a few are used on a regular basis. Get a list of rpms for mysql-5.1   Check for mysql version 5.1   $ rpm -qa |grep mysql | grep 5.1 mysql-test-5.1.52-1.el6_0.1.x86_64 mysql-connector-java-5.1.12-2.el6.x86_64 mysql-bench-5.1.52-1.el6_0.1.x86_64 mysql-server-5.1.52-1.el6_0.1.x86_64 mysql-connector-odbc-5.1.5r1144-7.el6.x86_64 mysql-5.1.52-1.el6_0.1.x86_64 mysql-libs-5.1.52-1.el6_0.1.x86_64 mysql-devel-5.1.52-1.el6_0.1.x86_64 Of course we can use egrep, and sort to get a more specific list $ rpm -qa |egrep -i "bash|ntpdate|httpd"|sort bash-4.1.2-8.el6.x86_64 ntpdate-4.2.4p8-2.el6.x86_64 xargs - build and execute command lines from standard input Now suppose we want to remove all the rpms found by the rpm query. Sometimes we can ...

How to Record and Play in Vim

Image
Have you ever been in the middle of editing something in vim, and noticed "recording" on the lower left of the screen? If you were in a hurry, you probably just continued typing, and thought, maybe I'll use that feature some day, but as long as it lets me continue I won't worry about it. Well it's really quite simple to use once you know the sequence. Here is a high level overview on how to use the macro recording feature of vim. High Level Steps to Record and Play a Macro in Vim 1. Press q to Start recording, followed by a lower case character to name the macro. 2. Perform any typical editing, actions inside Vim editor, which will be recorded. 3. Stop recording by pressing q. 4. Play the recorded macro by pressing @ followed by the macro name. 5. To repeat a macro multiple times, press : n @ macro name, where n is a number. For more details, check out a complete tutorial at thegeekstuff.com: Vim Macro Tutorial: How To Record and Play

Bash Shell, X, & Firefox Shortcuts

Image
As I was writing a script, I noticed that I pressed Shift-PageUp without even thinking about it. Then I realized that there are a lot of shortcuts we take for granted as Sysadmins. I thought it would be helpful to share some of them. This is not a comprehensive list, but a few shortcuts I find myself using all the time. Bash Shell shortcuts Shift-PageUp / PageDown See more of the screen Ctrl-a, Ctrl-e Move to beginning / end of line up & down arrows See bash history !! / !$ Execute the previous command / parameter !n Execute the nth command in history Ctrl-D Logout, or exit Ctrl-u, Ctrl-h, Ctrl-b Delete previous char, or entire line Alt-F1 to Alt-F7 Switch to another console —see also: using-bash-history , ...

Bash Alias

Image
An alias is a built-in way of modifying the way a command works, or it is used as a shortcut for another command. For example, you may find that you often type "ls -l", or "ls -ltr", and think it would be nice if you could type less characters. You can create an alias, so that all you would have to type is "ll", instead of "ls -l." To add an alias to your .bashrc file: $ vi ~/.bashrc Insert these lines: alias ls='ls --color=tty' alias ll='ls -l' In order for the new alias to take effect, you can open a new console, login again, or simply source your .bashrc file. You also have the option of running bash again to open a new shell, or just running the alias command. What do I mean by source the file? You can either run a script, or have the shell read the variables in a script without actually running it. This is called sourcing a file, and is accomplished by typing either "source", or "." followed by th...

Find Subnet Mask with ipcalc

An easy way to convert a subnet mask from bit notation (e.g. /24) to dotted decimal notation is to use ipcalc from any linux box. The -m option displays the subnet mask. $ ipcalc -m 10.10.10.128/25 NETMASK=255.255.255.128 $ O.K., that's fine, you say, but how do I know how many hosts are on the subnet? That's easy enough -- just use the -b option to find the broadcast address. $ ipcalc -b 10.10.10.128/25 BROADCAST=10.10.10.255 The range of IP's will be from one more than the network address up to one less than the broadcast address. In the example above the IP address range is 129-254. Often the gateway is the first or last address in the range to avoid confusion. If you don't have access to a linux box, you can always do a google search for "subnet calc," where you can probably find an online subnet calculator. For the opposite calculation - find prefix from subnet mask, use the -p option. $ ipcalc -p 10.10.10.128 255.255.255.128 PREFIX=25 $ There y...

Convert a Text File to HTML

Image
While considering how to make my shell scripts look better on the web, I started looking at freshmeat.net for programs that would convert source code to html. Then I thought, vim already has syntax highlighting. I wonder if it has a way to convert to html. Sure enough, it can be done with a single command: :runtime! syntax/2html.vim Convert Text File to HTML :runtime! syntax/2html.vim : convert txt to html :h 2html : help about 2html :wq! : write the new file The current file is converted, and an .html extension is added. Once the file is saved, it can be opened in a browser. For more vi tips, check out: http://systemnotesorg.blogspot.com/search/label/vi And the official vim site: http://www.vim.org/tips , Here is a beautiful example of C source code that was quickly converted to HTML, while preserving all of vim's color coding: http://systemnotes.org/download/matrix/matrix.c.html

Mail a Text File from the Shell

Image
Would you like an easy way to send files to someone outside of your local network, or quickly test a mail server? Well the old "mail" command is still available, and it comes in handy for sending config files, or using within a shell script. This is all you need: $ mail -s test me@company.com That's the shortcut. If you want more details, you can read the rest of the post... Using the mail command 1) Use Mail Interactively to read mail a) type Mail b) enter the number of the message to read, press enter c) press space to page down, n for next message d) ? for help e) q to quit 2) Use mail Interactively to send mail a) type mail command followed by email address b) Enter subject, press enter c) Enter text of message d) press Ctrl-d on a line by itself when finished e) Enter CC: if desired, or press Ctrl-d again $ mail user@company.com Subject: test Here is my test message <Ctrl-d> Cc: <Ctrl-d>$ For a little less work, add the subject to the command prompt. ...

Vim Tips -- Search and Replace

Image
Did you ever wonder if there was an easy way to send an example file for someone to look at, but still keep your private information safe? Sure you can use a sed, or perl one-liner, as I discussed: using-bash-and-sed-to-modify-text-file.html , but why not use search and replace in vi / vim before publishing your info? That way you can see exactly what you are changing. Remember, while vim is installed by default on most Linux distros, is also available for Windows, and it is free -- http://www.vim.org Suppose you have part of a log file, or nmap output that contains real hostnames, a real domain name, and real IP addresses. You want someone to help you troubleshoot something, but you don't what to give the real info for everyone to see. Start with the info in a text file, such as this: Host realhost-1.realdomain.com (192.168.0.54) appears to be up. Host realhost-2.realdomain.com (192.168.0.55) appears to be up. Host realhost-3.realdomain.com (192.168.0.56) appears to be up. Host...

Ping Multiple Hosts Using Bash Nmap and Fping

Image
I explained how to get a list of hosts using nmap -- using-nmap-to-generate-host-lists.html , but here is another look at the subject. The question is, how do I ping multiple hosts to find out which ones are down? Sure this could be considered a topic of system monitoring, but maybe you just want to reboot a bunch of machines, and make sure they all come back online. This quick check will tell you whether there is a problem or not. Here are three methods for pinging a list of hosts: 1.) for host in `cat all.txt `;do ping -c 1 $host; done 2.) nmap -sP -R -iL all.txt 3.) sudo fping -u < xyz/all.txt First, we assume that you have a text file named all.txt that contains a list of hostnames, one per line. Obviously, the examples here contain fake hostnames, domain names and IPs, as described in another article about vi: vim-tips-search-and-replace.html . --- all.txt --- xyz-1 xyz-2 xyz-3 xyz-4 xyz-5 xyz-6 xyz-7 xyz-8 --- end all.txt --- 1.) Use a for loop in ...

Shell Console Reset

Image
Did you ever cat a file that caused the terminal to display all kinds of strange characters? Pressing Ctrl-C and Enter, or typing clear doesn't get the console back to normal. The characters are there, but they are unreadable. A quick way to fix this is to use "reset" -- type: $ reset That should bring the console back to normal. Of course, if you just want to clear the screen, you can type "clear" ("cls" in DOS, or a Windows command prompt).

Defeat Telemarketers for FREE!

Image
While researching anti-spam techniques, I came across an anti-telemarketing technique that has proved quite useful. Within a few weeks, it noticeably reduced the amount of telemarketer calls I was getting. Here is the original article, which I copied: The original site seems to be down ( http://home.comcast.net/~dakine_101798/spambeater.htm ): so I have a copy on my systemnotes.org site -- http://www.systemnotes.org/notes/security/Defeat_Telemarketers_for_FREE.html Defeat Telemarketers for FREE! Yes! You can stop Telemarketers COLD! Now you can save that $40.00 you were thinking of spending on a TeleZapper . You can even save a couple bucks on the eBay Auctions for this sound file. The TeleZapper is a device that plays the first tone in the three tones that precede the telephone company's historic " This number has been disconnected " message. Most telemarketing predictive dialers listen for that tone, and when it is present t...

Beginner's Guide to the Vi editor

Image
The article linked below is a nice introduction to the Vi editor. People often ask why they have to learn vi, or vim. One important reason is that it is the editor most likely available on any linux or unix system you may have to manage as a sysadmin. Less experienced sysadmins may say that they can just install joe, or pico, or something similar -- until I show them 1200 linux boxes that we have to manage! Anyway, once you have the basics, you can add more knowledge as you go. First realize that there are two modes - command mode, and editing mode. "i" puts vi into editing mode, and [esc] goes back to command mode. You can get by with just a few commands at first: vi file.txt i (insert -- go into editing mode) [esc] (move around) [esc]:wq (save) [esc]:q! (quit without saving) read more | digg story Links: http://www-acs.ucsd.edu/info/vi_tutorial.php http://www.viemu.com/vi-vim-cheat-sheet.gif

Use CheckInstall Instead of Make Install

Did you ever look for a binary, and as a last resort download the source to compile yourself?   Of course you were disappointed that the program would not be part of your package management system. Usually you have to run something like this:   ./configure   make   make install An easy way to create an .rpm or .deb file from source is to run checkinstall instead of "make install" during the standard install from source. http://freshmeat.net/projects/checkinstall -- CheckInstall Freshmeat Page http://checkinstall.izto.org -- CheckInstall Home Page CheckInstall keeps track of all files installed by a "make install" or equivalent, creates a Slackware, RPM, or Debian package with those files, and adds it to the installed packages database, allowing for easy package removal or distribution.

Don't Torrent That iTunes Plus Song...

Image
Sure, you can now download music from the iTunes store without DRM but that doesn't mean you should just willy nilly start sharing that music with your friends. For one thing, it's illegal. For another, your account information is embedded into that m4a music file. Don't believe me? Try this yourself. The site is mostly for Mac users, but the strings command works in linux, and cygwin for Windows. This link has interesting comments as well. read more | digg story

Blogger Digest: Using VNC And Redhat Linux

VNC is an excellent way to remote control linux and Windows machines. Here is a description, and links to the programs. Blogger Digest: Using VNC And Redhat Linux x11vnc official site Real VNC Server official site TightVNC TightVNC software UltraVNC UltraVNC software

Did you know these basic Firefox Tips?

Image
You May know those BIG things But Did you know these? Excellent list of easy firefox tips to implement -- e.g., press Esc to stop animated gifs from moving... # To quickly find any word in a web page type /word it will highlight the word and press Ctrl+G to “Find Again” that same word again # If you wish to remove an item from your Address Bar Drop down menu,Highlight it without clicking and use Shift+Delete. # To stop animated gifs from moving, press the ESC key. read more | digg story

How to Use Peer to Peer Safely

Image
About P2P P2P software is free, and legal to install and use, but it does make sharing of copyrighted material easy to do, and that is not legal. Are people still using P2P software after Napster got shut down? Yes, they certainly are. Free music downloads? Free software? -- well be careful about copyrighted materials, but the technology is interesting nonetheless. One of the best ways to get a large file, such as a linux iso file, is to use bit torrent. Dangers What are the dangers, and inconveniences of using peer to peer file sharing software such as Limewire, eDonkey, Azureus, or Bittorrent? 1.) The content quality is only as good as how trustworthy the peers are 2.) Some content is copyrighted, and may be illegal to share or download on this type of network 3.) Content may contain viruses, trojans, and decoys 4.) Excessive traffic may cause your ISP to limit your bandwidth usage 5.) Some downloads may take days to complete 6.) There may be pornography disguised as something ...