Linux

Commands


Determine the Version of Redhat you are running

  • uname -a
  • cat /proc/version
    • (if you are curious about other stuff you can use these too)
    • cat /proc/cpuinfo
    • cat /proc/meminfo
  • cat /etc/redhat-release

Bash scripts to remove files older than 3 days

Method 1

You can use option -delete to remove files instead of tricks with rm and xargs.

Sample:
find /path/dir -name "*.bz2" -type f -Btime +30d -delete

Also keep in mind that file node (-type f) actually has three times: created, last accessed, last modified.

Method 2

find /u1/database/prod/arch -type f -mtime +3 -exec rm {} \; 

The "\;" at the end tells find where the end of the -exec command is. It can't just be the end of the line because the find command syntax allows further tests and actions after the -exec and it can't be just ; because the shell would see it as the end of a shell command and remove it. The \ "escapes" it from being seen by the shell as the end of a shell command.


Enable/Disable Services and run levels

On Debian Systems you can enable disable services and their run levels using:

sudo sysv-rc-conf

Ubuntu / Debian Linux: Services Configuration Tool to Start / Stop System Services

RHEL / CentOS uses - ntsysv command to setup boot service

ntsysv

update-rc.d like command on Redhat Enterprise / CentOS Linux


iptables stuff

To add rules to iptables at a specific place use the commands below:

iptables -I RH-Firewall-1-INPUT 11 -m state --state NEW -p tcp --dport 8080 -j ACCEPT
iptables -I RH-Firewall-1-INPUT 12 -m state --state NEW -p tcp --dport 8009 -j ACCEPT

To remove specific rules from iptables use:

iptables -D RH-Firewall-1-INPUT 12

To display iptables options on RH use:

service iptables 

and/or depending on path variable

/sbin/service iptables

http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch14_:_Linux_Firewalls_Using_iptables

Basic Iptables Options

Here are explanations for some of the iptables options you will see in this tutorial. Don't worry about understanding everything here now, but remember to come back and look at this list as you encounter new options later on.

  • -A - Append this rule to a rule chain. Valid chains for what we're doing are INPUT, FORWARD and OUTPUT, but we mostly deal with INPUT in this tutorial, which affects only incoming traffic.
  • -L - List the current filter rules.
  • -m conntrack - Allow filter rules to match based on connection state. Permits the use of the --ctstate option.
  • --ctstate - Define the list of states for the rule to match on. Valid states are:
    • NEW - The connection has not yet been seen.
    • RELATED - The connection is new, but is related to another connection already permitted.
    • ESTABLISHED - The connection is already established.
    • INVALID - The traffic couldn't be identified for some reason.
  • -m limit - Require the rule to match only a limited number of times. Allows the use of the --limit option. Useful for limiting logging rules.
    • --limit - The maximum matching rate, given as a number followed by "/second", "/minute", "/hour", or "/day" depending on how often you want the rule to match. If this option is not used and -m limit is used, the default is "3/hour".
  • -p - The connection protocol used.
  • --dport - The destination port(s) required for this rule. A single port may be given, or a range may be given as start:end, which will match all ports from start to end, inclusive.
  • -j - Jump to the specified target. By default, iptables allows four targets:
    • ACCEPT - Accept the packet and stop processing rules in this chain.
    • REJECT - Reject the packet and notify the sender that we did so, and stop processing rules in this chain.
    • DROP - Silently ignore the packet, and stop processing rules in this chain.
    • LOG - Log the packet, and continue processing more rules in this chain. Allows the use of the --log-prefix and --log-level options.
  • --log-prefix - When logging, put this text before the log message. Use double quotes around the text to use.
  • --log-level - Log using the specified syslog level. 7 is a good choice unless you specifically need something else.
  • -i - Only match if the packet is coming in on the specified interface.
  • -I - Inserts a rule. Takes two options, the chain to insert the rule into, and the rule number it should be.
  • -I INPUT 5 would insert the rule into the INPUT chain and make it the 5th rule in the list.
  • -v - Display more information in the output. Useful for if you have rules that look similar without using -v.
  • -s --source - address[/mask] source specification
  • -d --destination - address[/mask] destination specification
  • o --out-interface - output name] network interface name ([ for wildcard)
 =================================================================

http://wiki.centos.org/HowTos/Network/IPTables

Ports and Protocols

Above we have seen how we can add rules to our firewall to filter against packets matching a particular interface or a source IP address. This allows full access through our firewall to certain trusted sources (host PCs). Now we'll look at how we can filter against protocols and ports to further refine what incoming packets we allow and what we block.

Before we can begin, we need to know what protocol and port number a given service uses. For a simple example, lets look at bittorrent. Bittorrent uses the tcp protocol on port 6881, so we would need to allow all tcp packets on destination port (the port on which they arrive at our machine) 6881:

# Accept tcp packets on destination port 6881 (bittorrent)
 iptables -A INPUT -p tcp --dport 6881 -j ACCEPT

Here we append (-A) a rule to the INPUT chain for packets matching the tcp protocol (-p tcp) and entering our machine on destination port 6881 (--dport 6881).

Note: In order to use matches such as destination or source ports (--dport or --sport), you must first specify the protocol (tcp, udp, icmp, all).

We can also extend the above to include a port range, for example, allowing all tcp packets on the range 6881 to 6890:

# Accept tcp packets on destination ports 6881-6890
 iptables -A INPUT -p tcp --dport 6881:6890 -j ACCEPT

List Hardware:

lshw

---

Tar

http://www.linfo.org/tar.html


To create a gzipped tar file

tar -pczf name_of_your_archive.tar.gz /path/to/directory

PmWiki

pmwiki.org

Blix theme adapted by David Gilbert, powered by PmWiki