PREVIOUS NEXT
Search for mail exchanger (MX) records using dig
Mail exchanger or MX records in DNS are used to route email for a domain. The dig utility makes it easy to search for this type of DNS record.To search for the MX records for the domain tech-recipes.com, use:
dig mx tech-recipes.com
This will query the DNS server configured in your operating system. Often times it is useful to query against a different DNS server. To perform the same query above against the name server ns3.notarealdomain.com:
dig @ns3.notarealdomain.com mx tech-recipes.com... Read More
DNS/BIND: Create a basic zone file
A zone file holds the DNS resource records for all of the domain names associated with the zone. Zone files store all of the data served by a DNS server. This recipe describes the basic zone file format without any resource records suitable for any type of zone file.The zone file needs to be created within the DNS server's working directory. There is no requirement for filenames with zone file, but a reasonable standard is db.domain.name, the name of the domain preceded by db.
The basic format of the zone file is a time to live (TTL) field followed by the start of authority (SOA) records. The TTL instructs non-authoritative DNS servers how long to cache records retrieved from the zone file. The longer this period, the longer it will take to propagate changes to the zone files. The shorter the TTL, the harder your DNS servers will work beacuse non-authoritative servers will have to ask it the same question more frequently. Values from a few hours to a day are reasonable.
An integer TTL ... Read More
DNS/BIND resource record: Address (A) record
The address record (A record) maps a hostname and fully qualified domain name with an IP address.To add the host chef with IP address 192.168.5.100 to the domain tech-recipes.com. in the zone file for tech-recipes.com, use the following format:
chef.tech-recipes.com. IN A 192.168.5.100
Please note the period following the domain name in the record. This is critical beacuse it tells BIND that the domain name is attached and complete (fully qualified). Without this period, BIND will add the domain name associated with the zone file to the end of this to create a record for chef.tech-recipes.com.tech-recipes.com. which is not what we want.
Because of this behavior, it is possible to use shorthand:
chef IN A 192.168.5.100
Whenever you add an address record (what could be called a forward lookup record) it is usually appropria... Read More
DNS/BIND resource record: PTR reverse lookup record
The PTR (pointer) record maps an IP address to a hostname and fully qualified domain name. Many applications use reverse lookups to identify the domain from which a TCP/IP connection is formed. Best practice for DNS is to create a PTR record for every A record.To associate the host chef.tech-recipes.com. with the IP address 192.168.5.10 to the domain tech-recipes.com. in the zone file db.5.168.192 with origin 5.168.192.in-addr.arpa., use the following format:
10 IN PTR chef.tech-recipes.com.
Please note the period following the domain name in the record. This is critical beacuse it tells BIND that the domain name is attached and complete (fully qualified). Without this period, BIND will add the domain name associated with the zone file to the end of this which would make chef.tech-recipes.com.5.168.192.in-addr.arpa. which is not what we want.
Whenever you add an address record (what could be called a forward lookup record) it is usual... Read More
DNS/BIND resource record: routing mail with MX records
Proper DNS configuration with MX records is a requirement for routing email for a domain.When an email is sent to a domain, the sending mail server performs a DNS query to find the MX records associated with the recipient's domain. MX records have a preference value (numeric from 0-65535). The sending mail server tries the lowest preference value MX record first. If that server is not reachable, the MX record with the second lowest preference is tried, and so on until a connection is made or no MX records remain.
The following three mail servers listed in order of preference are to be configured in the code below:
mx1.tech-recipes.com. (primary mail relayer)
mx2.tech-recipes.com. (secondary mail relayer)
mxbackup.offsite.domain. (tertiary mail relayer, offsite)
tech-recipes.com. mx 10 mx1.tech-recipes.com.
tech-recipes.com. mx 20 mx2.tech-recipes.com.
tech-recipes.com. mx 30 ... Read More
DNS/BIND: set TTL for individual resource records
BIND resource records allow an explict TTL value that will override the zone file's TTL for that specific resource record. One use for this is to prevent non-authoritative servers from caching these records, perhaps in prelude to changing a server's IP address.To set the TTL for an address record to 1 (the minimum recommended value), use:
chef.tech-recipes.com. 1 IN A 192.168.5.100
Other resource records can have the overriding TTL set in the same manner:
tech-recipes.com. 1 IN MX 10 mx1.tech-recipes.com.... Read More
DNS/BIND resource record: CNAME, canonical names, host aliases
A single host may have multiple personalities: web server (www), mail server (mail, mx), dns server (ns), ftp server (ftp). Rather than assign each of these names an address (A) record pointing to the same IP address, all of which would need to be changed if the IP address changed, one name can be associated with an address record and the remaining names can be aliases for that name. The CNAME record simplifies DNS management, and who doesn't want that?Given the following address record:
chef.tech-recipes.com. IN A 192.168.5.100
To add host aliases ftp and www pointing to chef, use the following resource records:
ftp.tech-recipes.com. IN CNAME chef.tech-recipes.com.
www.tech-recipes.com. IN CNAME chef.tech-recipes.com.
Within the same domain name which is the same domain associated with the zone file, these can be shortened to:
chef IN A 192.168.5.100
ftp ... Read More
DNS/BIND resource record: using $GENERATE to make many records
A cool feature in versions of BIND since 8.2 and 9.1 is the $GENERATE directive which can create hundreds or thousands of resource records with a single line in zone file. A common use for $GENERATE is assigning PTR records for a DHCP address range.Given the subnet 192.168.2.0/24 which is reserved (with the exception of reserved addresses 192.168.2.1-10) for use by a DHCP server pool, reverse lookup (PTR) records of the format dhcp#.tech-recipes.com. (where # is the address) can be created with the following line in the zone file:
$GENERATE 11-254 $ PTR dhcp$.tech-recipes.com.
This will generate the following records:
11 PTR dhcp11.tech-recipes.com.
12 PTR dhcp12.tech-recipes.com.
13 PTR dhcp13.tech-recipes.com.
...
253 PTR dhcp253.tech-recipes.com.
254 PTR dhcp254.tech-recipes.com.
Th... Read More
Mounting ISO images under freebsd
This command is useful for mounting ISO images under FreeBSD.
You have to the vnode driver in your kernel or loaded as a module.
Check for vn driver with "kldstat -v" command:
% kldstat -v | grep vn
8 vn
%
Configure vnode disk:
% vnconfig -v /dev/vn0c image.iso
Mount the virtual disk:
% mount -r -t cd9660 /dev/vn0c /mnt
Access/Check what you need then unmount the disk:
% umount /mnt
Clear the vnode disk:
% vnconfig -u -v /dev/vn0c... Read More
Show media type supported by an interface
This command is useful for showing the valid media options for an interfaceifconfig -m ep0
ep0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet 161.81.18.66 netmask 0xfffffff8 broadcast 161.81.18.71
ether 00:12:ff:97:a1:86
media: Ethernet 10baseT/UTP
supported media:
media 10baseT/UTP
media 10base5/AUI
In this case the interface only has two options twisted pair and AUI (aka thicknet)
this is a 3com 3c509 card
ifconfig -m fxp0
fxp0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
inet 161.81.22.103 netmask 0xffffff00 broadcast 161.81.22.255
ether 00:91:44:ec:3f:17
&nb... Read More
eject a cdrom in freebsd
This is the way via software to eject a cdrom under freebsdFor ATA (IDE/EIDE) cdroms the device is /dev/acd0c and the command looks like this:
cdcontrol -f /dev/acd0c eject
For SCSI cdroms the device is /dev/cd0c and the command would be:
cdcontrol -f /dev/cd0c eject
I do not have a usb cdrom so I am not sure what that one would look like. Please post a comment if you have seen that one.... Read More
using camcontrol to find information and dynamically add/remove SCSI devices
camcontrol is a very useful command for finding information and for adding and removing SCSI devices.Find what CAM SCSI busses exist and what devices are connected to them:
# camcontrol devlist
<eUSB Compact Flash 5.07 > at scbus0 target 0 lun 0 (pass0,da0)
<EXABYTE EXB-8505SMBANSH2 0793 > at scbus1 target 3 lun 0 (pass1,sa0)
<IBM CDRM00203\000\000\000\000\000!K BZ26 > at scbus1 target 6 lun 0 (pass2,cd0)
#
Notice that the USB bus on my system is considered a CAM SCSI bus.
I have two busses here. Bus 0 (USB) has a compact flash reader on it at target 0.
Bus 1 (SCSI) has a tape drive (sequential access device: sa0) at target 3 and a
cdrom drive (cd0) at target 6.
Let's say that we want to temporarily take the tape drive off without rebooting the
system and go backup another system. Since we only have a tape drive and
a cdrom drive this is pretty safe (disk drives with mounted filesystems would be
a differen... Read More
Using ipfilter to alter nmap OS detection results
nmap is often used to perform OS detection on remote systems if it cannot be determined by other means. It sends tcp packets which have problems and detects how each handles the errors. By tweaking things in ipflter we can trick nmap into thinking it is dealing with some other OS or be less certain about it's guess. Some additional resource are usually available in the OS sysctl variables (FreeBSD) and ndd settings (solaris) to help control things also. These examples were designed for FreeBSD but these (or variations) may work on other OS's as well.
For those who are unfamiliar with ipfilter syntax:
block in log quick on fxp0 proto tcp from any to any flags FUP
block - not allow the packet to proceed on through ipfilter
in - incoming from outside of the system
log - write any matches of this rule to the logfile
quick - if this rule matches immediately apply it do not drop through the rest of the rules
on fxp0 - the interface from ifconfig that this rules applies to
proto tcp - the tcp... Read More
Enable vi ksh command line editing
The Korn shell has the ability to utilize vi editor commands to edit commands in your history. If you are familiar with the vi editor, you will love this feature.To enable vi editing, type the following command or place it in your .kshrc file:
set -o vi
Then you can use vi commands. Press escape to enter vi command mode then you have access to many vi commands. For example, k will move up through previous commands in the history, /tail will search for the most recent command containing the word tail and pressing n will find the next occurence of that search term.
Once you have found a command that you want to repeat, just press ENTER and it will be run again. You can edit the command with R to replace characters from your current position, x to delete the current character, i to insert characters before the current character, a append characters after the current character, and $ to move to the end of the command.... Read More
Creating a kornshell script with text-based menus in VI
This recipe give a quick run-through on how to create text based menus for ksh scripts in VI. My experience is with IBM AIX 4.x. This a very, very basic recipe.
Create a new file (for example, test.ksh)
by typing: vi test.ksh
the file test.ksh will be created and opened in VI.
in this file, we will add the following lines (i will explain each below)
________
clear
print "TEST Script MENU"
PS3="Test Menu, enter choice:"
select clean_menu in "View script" "Edit script" "Print script" "Exit"
do
case $clean_menu in
"View script")
pg test.ksh;;
"Edit script")
vi test.ksh;;
"Print Report")
lp test.ksh;;
"Exit") break ;;
esac
done
_____
This will look like this when ran!
TEST Script MENU
1) View script
2) Edit script
3) Print script
4) Exit
Test Menu, enter choice:
this a super basic menu driven script.
_____
PS3= : what will show at the bottom, usually i have the name of the script (in my example, Test Menu, enter choice:)
select case_menu ... : can be whatever you choose to be, just be sure... Read More
Some Common AIX/Unix Commands
This is more of an ingredients list than a true recipe.
Here are some common AIX commands that i've come to love and hate. lsps a list paging space
lsattr El mem0 list current physical memory
extendlv hd6 16 doubled paging space from 512MB to 1024MB
(only use with IBM direction)
smit lsmksysb (list files on a tape from a mksysb)
lsdev Cc disk (shows all disk drives)
lscfg vl hdisk1 (shows info on individual disk drives, s/n, p/n, etc)
lspv shows disks installed on system
df k (shows file system size information)
lp filename (prints file to network printer)
lpstat (shows print jobs)
cancel # (cancels print job by #, found with lpstat)
enq U (restarts print que if status shows it is downmust be root)
enq Q prtx -#xxx (redirects a print job to another print que)
ps ef (shows current system processes)
errpt a (shows system error report including power outages)
errclear 0 (completely clears the system errlog viewed with errpt a)
errclear N sysplanar0 0
(clears only... Read More
appending a list of files to one file using xargs command
This recipe explains how to use the xargs command in ksh to work with multiple files. This recipe will show how to combine 10 files together into one file without manually doing a: cat file1 > bigfile, cat file2 >> bigfile, etc. The uses of this command are wide and very helpful; a great way to work with large amounts of files (also avoids the parameter list is too long message when trying to grep more than 1024 files)This is a very basic ksh command recipe.
If you work with AIX/Unix/ksh; most likely there are times when you need to do multiple things with files. This recipe will show how to append a list of files to one big file using two commands versus manually cat file1 > bigfile, then cat file2 >> bigfile, etc.
Files/Directory
ok, in my example; i am going to take the contents of 5 files and combine them into one big file.
so my files are: file1, file2, file3, file4, file5
the combined file will be called: bigfile.dat
also, i have all the files in the same directory (/usr... Read More
Checking if a variable is a number in ksh
Being able to test if a variable is a number in the Korn shell is very useful but not immediately obvious....Due to shell programming not using any kind of type checking you can sometimes end up not knowing if a variable is a number or a string. The script below will return TRUE or FALSE depending on the parameter passed to it.
#!/bin/ksh
#Stuart Brock 24.09.04
#
#Usage is isanum <PossibleNumber>
# e.g. isanum 4 -> TRUE
# isanum Not4 -> FALSE
#Will echo TRUE or FALSE depending on parameter
#
#Name Date Change
#---- ---- ------
#SGB 24.09.04 Created
#
#Notes:
expr $1 + 0 >/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "FALSE"
else
echo "TRUE"
fi
The code above works by adding zero to the variable using ... Read More
Determine Linux ethernet interface speed and duplex
Determine the autonegotiated ethernet connection speed and duplex using the mii-tool commandRunning the following command as superuser with no options will generate basic information about all of the ethernet interfaces on the computer:
mii-tool
The resulting output will look something like:
eth0: negotiated 100baseTx-FD, link ok
This output shows one interface (eth0) which was autonegotiated to 100 Mbps (100baseTx) and full duplex (FD).
Adding the -v option to the command generates verbose output and will tell you more about the interface including the manufacturer and model (if available) and the interface's capabilities.... Read More
Force the speed and duplex of a Linux ethernet interface
Using mii-tool, the speed and duplex of an ethernet interface can be set manually.You must set both the speed and duplex at the same time (it is not possible to autonegotiate only one). Typical combinations are:
100baseTx-FD 100baseTx-HD 10baseT-FD 10baseT-HD
To set 100 Mbps and full duplex on interface eth0, for example, use:
mii-tool -F 100baseTx-FD eth0... Read More