Hiển thị các bài đăng có nhãn Linux. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Linux. Hiển thị tất cả bài đăng

Bật dịch vụ SNMP trên VMWare ESXi 6.0/6.5

1. SSH đến ESXi hosting.

login as:
root Using keyboard-interactive authentication.
Password:
The time and date of this login have been sent to the system logs.

2. Gán SNMP community string.

[:~] esxcli system snmp set --communities YOUR_COMM_STRING

3. Bật dịch vụ SNMP

[:~] esxcli system snmp set --enable true

4. Thiết lập firewall

[:~] esxcli network firewall ruleset set --ruleset-id snmp --allowed-all trueAlready allowed all ip
[:~] esxcli network firewall ruleset set --ruleset-id snmp --enabled true

5. Khởi động dịch vụ SNMP

[:~] /etc/init.d/snmpd restart
root: snmpd Running from interactive shell, running command: esxcli system snmp set -e false.
root: snmpd setting up resource reservations.
root: snmpd opening firewall port(s) for notifications.
root: snmpd watchdog for snmpd started.

Mất khoảng 30-45'' để dịch vụ khởi động, bạn có thể thấy qua giao diện (GUI) dịch vụ running như hình bên dưới.

Lưu ý: dòng lệnh sau dùng để gởi SNMP đến subnet 192.168.0.0/24.

esxcli network firewall ruleset set --ruleset-id snmp --allowed-all false
esxcli network firewall ruleset allowedip add --ruleset-id snmp --ip-address 192.168.0.0/24
esxcli network firewall ruleset set --ruleset-id snmp --enabled true

How to Setup a Linux Firewall with PPPoE/NAT/iptables

How to Setup a Linux Firewall with PPPoE/NAT/iptables


PPPoE for Linux

Many Internet service providers are using the Point-to-Point Protocol over Ethernet (PPPoE) to provide residential Digital Subscriber Link (DSL) broadband Internet access. Most ISP’s do not support Linux and supply PPPoE clients only for Windows and Mac OS.
The PPPoE Protocol
PPPoE is a protocol for encapsulating PPP frames in Ethernet frames. PPP is a data-link-level protocol typically used to encapsulate network-level packets over an asynchronous serial line. This mode of usage is called asynchronous.
While PPP is a peer-to-peer protocol, PPPoE is initially a client-server protocol. The client (usually a personal computer) searches for a PPPoE server (called an access concentrator) and obtains the access concentrator’s MAC address and a session number. The process of setting up a PPPoE session is called discovery.
The Pseudo-TTY
The pppd program and the Linux kernel expect to transmit PPP frames over a TTY device. Luckily, UNIX (and Linux) support the concept of a pseudo-tty. This is a device which “looks” like a TTY, but instead of being connected to a physical terminal, it is connected to a UNIX process. Whenever something writes to the pseudo-tty, the data appears on the standard input of the back-end process. Whenever the back-end process writes to its standard output, the data may be read from the pseudo-tty.
Even more luckily, recent versions of pppd (2.3.7 and newer) support a pty option. This option automatically starts the back-end process and performs all the mundane operations required to connect it to a pseudo-tty. So to start the PPPoE link, you start pppd with the appropriate
pty option, which runs the pppoe executable connected to the pseudo-tty.
The MTU Problem
PPPoE introduces a real and annoying problem. The maximum Ethernet frame is 1518 bytes long. 14 bytes are consumed by the header, and 4 by the frame-check sequence, leaving 1500 bytes for the payload. For this reason, the Maximum Transmission Unit (MTU) of an Ethernet interface is usually 1500 bytes.
This is the largest IP datagram which can be transmitted over the interface without fragmentation. PPPoE adds another six bytes of overhead, and the PPP protocol field consumes two bytes, leaving 1492 bytes for the IP datagram. The MTU of PPPoE interfaces is therefore 1492 bytes.
When a TCP connection is initiated, each side can optionally specify the Maximum Segment Size (MSS). TCP chops a stream of data into segments, and MSS specifies the largest segment each side will accept. By default, the MSS is chosen as the MTU of the outgoing interface minus the usual size of the TCP and IP headers (40 bytes), which results in an MSS of 1460 bytes for an Ethernet interface.
TCP stacks try to avoid fragmentation, so they use an MSS which will not cause fragmentation on their outgoing interface. Unfortunately, there may be intermediate links with lower MTU’s which will cause fragmentation. Good TCP stacks perform path MTU discovery. In path MTU discovery, a TCP stack sets a special Don’t Fragment (DF) bit in the IP datagrams. Routers which cannot forward the datagram without fragmenting it are supposed to drop it and send an ICMP “Fragmentation-Required” datagram to the originating host.
The originating host then tries a lower MTU value. Unfortunately, many routers are anti-social and do not generate the fragmentation-required datagrams. Many firewalls are equally anti-social and drop all ICMP datagrams.
Now consider a client workstation on an Ethernet LAN connected to a PPPoE gateway. It opens a TCP connection to a web server. Because the Ethernet MTU is 1500, it suggests an MSS of 1460. The web server is also on an Ethernet and also suggests an MSS of 1460. The client then requests a web page. This request is typically small and reaches the web server. The server responds with many TCP segments, most of which are 1460 bytes long.
The maximum-sized segments result in 1500-byte IP datagrams and make their way to the DSL provider. The DSL provider cannot transmit a 1500-byte IP datagram over a PPPoE link, so it drops it (assume for now that the DF bit is set.) Furthermore, being anti-social, the DSL provider does not send an ICMP message to the web server.
The net result is that packets are silently dropped. The web client hangs waiting for data, and the web server keeps retransmitting until it finally gives up, or the connection is closed by the user aborting the web client.
One way around this is to artificially set an MSS for the default route on all LAN hosts behind the PPPoE gateway. This is annoying, as it requires changes on each host. Instead, rp-pppoe “listens in” on the MSS negotiation and modifies the MSS if it is too big. Adjusting the MSS is a hack. It breaks the concept of the transport-layer being end-to-end. It will not work with IPSec, because IPSec will not let you damage IP packets (they will fail to authenticate.) Nevertheless, it is a fairly effective solution to an ugly real-world problem, and is used by default in rp-pppoe.
Installation and Configuration of PPP / PPPoE
We setup a GENTOO 2005.0 Linux machine with RP-PPPoE, PPP and the Firewall Software iptables. The internal network 192.168.138.0 is mapped to the dynamically asigned IP address using NAT / IP-Masquerading.
  1. Download PPP from Sambas Site, on GENTOO Linux use:

    emerge ppp
    This creates the directory/etc/ppp
     
  2. Download RP-PPPoE from RoaringPenguin

    tar xzvf rp-pppoe-xxx.tar.gz
    cd src
    ./configure
    make
    make install

    cd /etc/ppp
    ls -l
    -rw-------  1 root root   37 Jul 25 09:59 chap-secrets
    -rw-------  1 root root    0 Jul 25 09:59 chap-secrets-bak
    -rw-------  1 root root   78 Jul 25 09:42 chap-secrets.example
    -rw-r--r--  1 root root  353 Jul 25 09:42 chat-default
    -rw-r--r--  1 root root  938 Jul 25 09:53 firewall-masq
    -rw-r--r--  1 root root  836 Jul 25 09:53 firewall-standalone
    -rwxr-xr-x  1 root root  931 Jul 25 09:42 ip-down*
    -rwxr-xr-x  1 root root 1081 Jul 25 09:42 ip-up*
    -rw-r--r--  1 root root    5 Jul 25 09:42 options
    -rw-r--r--  1 root root   53 Jul 25 09:42 options-pppoe
    -rw-r--r--  1 root root  238 Jul 25 09:42 options-pptp
    -rw-------  1 root root   37 Jul 25 09:59 pap-secrets
    -rw-------  1 root root    0 Jul 25 09:59 pap-secrets-bak
    -rw-------  1 root root   77 Jul 25 09:42 pap-secrets.example
    drwxr-xr-x  2 root root 4096 Jul 25 09:42 peers/
    drwxr-xr-x  2 root root 4096 Jul 25 09:53 plugins/
    -rw-r--r--  1 root root 4592 Jul 25 09:59 pppoe.conf
    -rw-------  1 root root 4562 Jul 25 09:59 pppoe.conf-bak
    -rw-r--r--  1 root root  104 Jul 25 09:53 pppoe-server-options
How to Connect
  1. Set up your Ethernet hardware

    First, make sure the Ethernet card you intend to use with the modem is visible to the Linux kernel.

    ifconfig eth0

    should display something like this:

    eth0 Link encap:Ethernet HWaddr 00:60:67:62:31:D4

    plust some more lines. Your HWaddr will be different. DO NOT assign an IP address to the Ethernet card. DO NOT configure the card to come up at boot time.
     Note, that the PPP-Interface (ppp0) is automatically setup by PPPoE/PPP, it cannot be setup manually.
     
  2. Configure various files

    Several files need editing. The easiest way to do this is to run the following command as root:

    adsl-setup

    Answer the questions and you should be all set. If you want to know what goes on behind, continue reading.
     
  3. Edit pap-secrets

    "xx.xyz@domain.ch" * "xxxxxxx"

    Edit the "pap-secrets" file, inserting your proper user-ID and password. Install the file (or copy the relevant lines) to /etc/ppp/pap-secrets. Your ISP may use CHAP authentication. In this case, add the line to /etc/ppp/chap-secrets.
     
  4. Edit pppoe.conf
    The file /etc/ppp/pppoe.conf contains configuration information for the ADSL connection.

    #***********************************************************************
    #
    # pppoe.conf
    #
    # Configuration file for rp-pppoe.  Edit as appropriate and install in
    # /etc/ppp/pppoe.conf
    #
    # NOTE: This file is used by the adsl-start, adsl-stop, adsl-connect and
    #       adsl-status shell scripts.  It is *not* used in any way by the
    #       "pppoe" executable.
    #
    # Copyright (C) 2000 Roaring Penguin Software Inc.
    #
    # This file may be distributed under the terms of the GNU General
    # Public License.
    #
    # LIC: GPL
    # $Id: pppoe.conf,v 1.10 2002/04/09 17:28:38 dfs Exp $
    #***********************************************************************

    # When you configure a variable, DO NOT leave spaces around the "=" sign.
    # Ethernet card connected to ADSL modem
    ETH='eth0'

    # ADSL user name.  You may have to supply "@provider.com"  Sympatico
    # users in Canada do need to include "@sympatico.ca"
    # Sympatico uses PAP authentication.  Make sure /etc/ppp/pap-secrets
    # contains the right username/password combination.
    # For Magma, use xxyyzz@magma.ca

    USER='xx.xyz@domain.ch'

    # Bring link up on demand?  Default is to leave link up all the time.
    # If you want the link to come up on demand, set DEMAND to a number indicating
    # the idle time after which the link is brought down.

    DEMAND=no
    #DEMAND=300

    # DNS type: SERVER=obtain from server; SPECIFY=use DNS1 and DNS2;
    # NOCHANGE=do not adjust.
    DNSTYPE=SPECIFY

    # Obtain DNS server addresses from the peer (recent versions of pppd only)
    # In old config files, this used to be called USEPEERDNS.  Changed to
    # PEERDNS for better Red Hat compatibility
    PEERDNS=no

    DNS1=195.186.4.111
    DNS2=195.186.1.111

    # Make the PPPoE connection your default route.  Set to
    # DEFAULTROUTE=no if you don't want this.

    DEFAULTROUTE=yes

    ### ONLY TOUCH THE FOLLOWING SETTINGS IF YOU'RE AN EXPERT

    # How long adsl-start waits for a new PPP interface to appear before
    # concluding something went wrong.  If you use 0, then adsl-start
    # exits immediately with a successful status and does not wait for the
    # link to come up.  Time is in seconds.
    #
    # WARNING WARNING WARNING:
    #
    # If you are using rp-pppoe on a physically-inaccessible host, set
    # CONNECT_TIMEOUT to 0.  This makes SURE that the machine keeps trying
    # to connect forever after adsl-start is called.  Otherwise, it will
    # give out after CONNECT_TIMEOUT seconds and will not attempt to
    # connect again, making it impossible to reach.

    CONNECT_TIMEOUT=30

    # How often in seconds adsl-start polls to check if link is up
    CONNECT_POLL=2

    # Specific desired AC Name
    ACNAME=

    # Specific desired service name
    SERVICENAME=

    # Character to echo at each poll.  Use PING="" if you don't want
    # anything echoed

    PING="."

    # File where the adsl-connect script writes its process-ID.
    # Three files are actually used:
    #   $PIDFILE       contains PID of adsl-connect script
    #   $PIDFILE.pppoe contains PID of pppoe process
    #   $PIDFILE.pppd  contains PID of pppd process

    CF_BASE=`basename $CONFIG`
    PIDFILE="/var/run/$CF_BASE-adsl.pid"

    # Do you want to use synchronous PPP?  "yes" or "no".  "yes" is much
    # easier on CPU usage, but may not work for you.  It is safer to use
    # "no", but you may want to experiment with "yes".  "yes" is generally
    # safe on Linux machines with the n_hdlc line discipline; unsafe on others.

    SYNCHRONOUS=no

    # Do you want to clamp the MSS?  Here's how to decide:
    # - If you have only a SINGLE computer connected to the ADSL modem, choose
    #   "no".
    # - If you have a computer acting as a gateway for a LAN, choose "1412".
    #   The setting of 1412 is safe for either setup, but uses slightly more
    #   CPU power.
    CLAMPMSS=1412
    #CLAMPMSS=no

    # LCP echo interval and failure count.
    LCP_INTERVAL=20
    LCP_FAILURE=3

    # PPPOE_TIMEOUT should be about 4*LCP_INTERVAL
    PPPOE_TIMEOUT=80

    # Firewalling: One of NONE, STANDALONE or MASQUERADE
    FIREWALL=NONE

    # Linux kernel-mode plugin for pppd.  If you want to try the kernel-mode
    # plugin, use LINUX_PLUGIN=/etc/ppp/plugins/rp-pppoe.so

    LINUX_PLUGIN=

    # Any extra arguments to pass to pppoe.  Normally, use a blank string
    # like this:

    PPPOE_EXTRA=""

    # Rumour has it that "Citizen's Communications" with a 3Com
    # HomeConnect ADSL Modem DualLink requires these extra options:

    # PPPOE_EXTRA="-f 3c12:3c13 -S ISP"

    # Any extra arguments to pass to pppd.  Normally, use a blank string
    # like this:
    PPPD_EXTRA=""

    ########## DON'T CHANGE BELOW UNLESS YOU KNOW WHAT YOU ARE DOING
    # If you wish to COMPLETELY overrride the pppd invocation:
    # Example:
    # OVERRIDE_PPPD_COMMAND="pppd call dsl"

    # If you want adsl-connect to exit when connection drops:
    # RETRY_ON_FAILURE=no
     
  5.  Set up DNS

    If you are using DNS servers supplied by your ISP, edit the file /etc/resolv.conf
     
  6. Bring up the connection at boot time (For GENTOO)

    #!/sbin/runscript
    depend() {
    need net
    use logger dns
    }

    # Paths to programs
    START=/usr/sbin/adsl-start
    STOP=/usr/sbin/adsl-stop
    STATUS=/usr/sbin/adsl-status

    start() {
    ebegin "Bringing up ADSL link"
    $START &>/dev/null
    touch /var/lock/subsys/adsl
    eend $?
    }

    stop() {
    ebegin "Shutting down ADSL link"
    $STOP &>/dev/null
    rm -f /var/lock/subsys/adsl
    eend $?
    }
     
  7. Commands to control the ADSL link
    As root, bring up the link by typing: adsl-start
    As root, bring down the link by typing: adsl-stop
    ps -ef
    /usr/sbin/adsl-connect
    /usr/sbin/pppd pty /usr/sbin/pppoe -p /var/run/pppoe.conf-adsl.pid.pppoe \
       -I eth0 -T 80 -U -m 1412 noipdefa
    /usr/sbin/pppoe -p /var/run/pppoe.conf-adsl.pid.pppoe \
       -I eth0 -T 80 -U -m 1412
    ifconfig -a
    eth0      Link encap:Ethernet  HWaddr 00:30:48:28:AA:4A
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:23529 errors:0 dropped:0 overruns:0 frame:0
              TX packets:18759 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:22942360 (21.8 Mb)  TX bytes:1973186 (1.8 Mb)
              Base address:0x3000 Memory:fc200000-fc220000

    eth1      Link encap:Ethernet  HWaddr 00:30:48:28:AA:4B
              inet addr:192.168.138.1  Bcast:192.168.138.255  Mask:255.255.255.0
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:18130 errors:0 dropped:0 overruns:0 frame:0
              TX packets:25373 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:1819853 (1.7 Mb)  TX bytes:21836499 (20.8 Mb)
              Base address:0x3040 Memory:fc220000-fc240000

    lo        Link encap:Local Loopback
              inet addr:127.0.0.1  Mask:255.0.0.0
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:16 errors:0 dropped:0 overruns:0 frame:0
              TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:1590 (1.5 Kb)  TX bytes:1590 (1.5 Kb)

    ppp0      Link encap:Point-to-Point Protocol
              inet addr:213.3.5.17  P-t-P:195.186.253.131  Mask:255.255.255.255
              UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1492  Metric:1
              RX packets:21685 errors:0 dropped:0 overruns:0 frame:0
              TX packets:14272 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:3
              RX bytes:22260398 (21.2 Mb)  TX bytes:1314858 (1.2 Mb)
    netstat -nr
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
    195.186.253.131 0.0.0.0         255.255.255.255 UH        0 0          0 ppp0
    192.168.138.0   0.0.0.0         255.255.255.0   U         0 0          0 eth1
    127.0.0.0       127.0.0.1       255.0.0.0       UG        0 0          0 lo
    0.0.0.0         195.186.253.131 0.0.0.0         UG        0 0          0 ppp0
    adsl-status
    adsl-status: Link is up and running on interface ppp0
    ppp0      Link encap:Point-to-Point Protocol
              inet addr:213.3.5.17  P-t-P:195.186.253.131  Mask:255.255.255.255
              UP POINTOPOINT RUNNING NOARP MULTICAST  MTU:1492  Metric:1
              RX packets:2432 errors:0 dropped:0 overruns:0 frame:0
              TX packets:2145 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:3
              RX bytes:628102 (613.3 Kb)  TX bytes:241917 (236.2 Kb)

Using A Zyxel Router as a Modem (Bridged Mode)

Connect to your Zyxel Router using TELNET. In Menu 1, change Route IP = No, Bridge = Yes.
In Menu 4, change Encapsulation to RFC 1483. Make sure VPI and VCI are setup correct for your Provider.
In Menu 11.2, change Route = None, Bridge = Yes.

Now, reboot the Modem ... it's now a Modem no more a Router. All settings are ignored, the Modem can no longer talk PPPoE!

Linux Routing

The first task to undertake when configuring the firewall ruleset is to turn on all the options you would like the kernel to use when processing IP packets. The very first thing is that you turn ip_forwarding off - it will be turned on after everything is done. We have set the following kernel options in the /etc/conf.d/local.start.
# /etc/conf.d/local.start:
# Setup Kernel Options for iptables/Firewall"

# If your firewall has a dynamic IP address, use this setting
echo 2 > /proc/sys/net/ipv4/ip_dynaddr

# Hardening settings:
if [ -e /proc/sys/net/ipv4/conf/all/accept_source_route ]; then
  for f in /proc/sys/net/ipv4/conf/*/accept_source_route
  do
   echo 0 > $f
  done
fi


# Do not respond to 'redirected' packets
if [ -e /proc/sys/net/ipv4/conf/all/send_redirects ]; then
  for f in /proc/sys/net/ipv4/conf/*/send_redirects
  do
   echo 0 > $f
  done
fi


# Do not reply to 'proxyarp' packets
if [ -e /proc/sys/net/ipv4/conf/all/proxy_arp ]; then
  for f in /proc/sys/net/ipv4/conf/*/proxy_arp
  do
   echo 0 > $f
  done
fi


# Detecting and stopping spoofed packets
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter
if [ -e /proc/sys/net/ipv4/conf/all/rp_filter ]; then
  for f in /proc/sys/net/ipv4/conf/*/rp_filter
  do
   echo 1 > $f
  done
fi


# Ignore source routing (dictating what route the traffic will take)
# from the origin of the packet as dictated by the client

echo 0 > /proc/sys/net/ipv4/conf/all/accept_source_route
if [ -e /proc/sys/net/ipv4/conf/all/accept_source_route ]; then
  for f in /proc/sys/net/ipv4/conf/*/accept_source_route
  do
   echo 0 > $f
  done
fi


# Suppress ICMP redirects
if [ -e /proc/sys/net/ipv4/conf/all/accept_redirects ]; then
  for f in /proc/sys/net/ipv4/conf/*/accept_redirects
  do
   echo 0 > $f
  done
fi
if [ -e /proc/sys/net/ipv4/conf/all/send_redirects ]; then
  for f in /proc/sys/net/ipv4/conf/*/send_redirects
  do
   echo 0 > $f
  done
fi
if [ -e /proc/sys/net/ipv4/conf/all/secure_redirects ]; then
  for f in /proc/sys/net/ipv4/conf/*/secure_redirects
  do
   echo 0 > $f
  done
fi


echo 1 > /proc/sys/net/ipv4/conf/all/log_martians
echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_broadcasts
echo 0 > /proc/sys/net/ipv4/icmp_echo_ignore_all
echo 1 > /proc/sys/net/ipv4/icmp_ignore_bogus_error_responses
echo 1 > /proc/sys/net/ipv4/ip_forward

NAT (Network Address Translation)

Normally, packets on a network travel from their source to their destination through many different links. None of these links really alter your packet: they just send it onward.
If one of these links were to do NAT, then they would alter the source or destinations of the packet as it passes through. As you can imagine, this is not how the system was designed to work, and hence NAT is always something of a crock. Usually the link doing NAT will remember how it mangled a packet, and when a reply packet passes through the other way, it will do the reverse mangling on that reply packet, so everything works.
Why Would I Want To Do NAT?
In a perfect world, you wouldn't. Meanwhile, the main reasons are:
  • Modem Connections To The Internet
Most ISPs give you a single IP address when you dial up to them. You can send out packets with any source address you want, but only replies to packets with this source IP address will return to you. If you want to use multiple different machines (such as a home network) to connect to the Internet through this one link, you'll need NAT.
This is by far the most common use of NAT today, commonly known as «masquerading» in the Linux world. I call this SNAT, because you change the source address of the first packet.
  • Multiple Servers
Sometimes you want to change where packets heading into your network will go. Frequently this is because (as above), you have only one IP address, but you want people to be able to get into the boxes behind the one with the real IP address. If you rewrite the destination of incoming packets, you can manage this. This type of NAT was called port-forwarding under previous versions of Linux.
  • Transparent Proxying
Sometimes you want to pretend that each packet which passes through your Linux box is destined for a program on the Linux box itself. This is used to make transparent proxies: a proxy is a program which stands between your network and the outside world, shuffling communication between the two. The transparent part is because your network won't even know it's talking to a proxy, unless of course, the proxy doesn't work. Squid can be configured to work this way, and it is called redirection or transparent proxying under previous Linux versions.
The Two Types of NAT
NAT is divided into two different types: Source NAT (SNAT) and Destination NAT (DNAT).
  • SNAT
Source NAT is when you alter the source address of the first packet: i.e. you are changing where the connection is coming from. Source NAT is always done post-routing, just before the packet goes out onto the wire. Masquerading is a specialized form of SNAT.
  • DNAT
Destination NAT is when you alter the destination address of the first packet: i.e. you are changing where the connection is going to. Destination NAT is always done before routing, when the packet first comes off the wire. Port forwarding, load sharing, and transparent proxying are all forms of DNAT.
Examples
Here are our NAT rules as examples.
# echo "Static NAT: Masquerade our Traffic"
# $IPTABLES -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

echo "Static NAT to IP: 213.3.5.17"
$IPTABLES -t nat -A POSTROUTING -o ppp0 -j SNAT --to 213.3.5.17


echo "DNAT Portforwarding: 25 --> 192.168.138.28:25"
$IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 25 -j DNAT --to 192.168.138.28:25

echo "DNAT Portforwarding: 53 --> 192.168.138.20:25"
$IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 53 -j DNAT --to 192.168.138.20:53
$IPTABLES -t nat -A PREROUTING -p udp -i ppp0 --dport 53 -j DNAT --to 192.168.138.20:53

echo "DNAT Portforwarding: 80 --> 192.168.138.21:80"
$IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 80 -j DNAT --to 192.168.138.21:80

Firewall with netfilter/iptables

netfilter and iptables are building blocks of a framework inside the Linux 2.4.x and 2.6.x kernel. This framework enables packet filtering, network address translation and other packet mangling. It is the re-designed and heavily improved successor of the previous Linux 2.2.x ipchains and Linux 2.0.x ipfwadm systems.
netfilter is a set of hooks inside the Linux kernel that allows kernel modules to register callback functions with the network stack. A registered callback function is then called back for every packet that traverses the respective hook within the network stack.
iptables is a generic table structure for the definition of rulesets. Each rule within an IP table consists of a number of classifiers (iptables matches) and one connected action (iptables target).
Main Features
  • stateless packet filtering (IPv4 and IPv6)
  • stateful packet filtering (IPv4)
  • all kinds of network address and port translation (NAT/NAPT)
  • flexible and extensible infrastructure
  • multiple layers of API's for 3rd party extensions
  • large number of plugins/modules kept in 'patch-o-matic' repository
What can I do with netfilter/iptables?
  • build internet firewalls based on stateless and stateful packet filtering
  • use NAT and masquerading for sharing internet access if you don't have enough public IP addresses
  • use NAT to implement transparent proxies
  • aid the tc and iproute2 systems used to build sophisticated QoS and policy routers
  • do further packet manipulation (mangling) like altering the TOS/DSCP/ECN bits of the IP header
An iptable tutortial can be found here.
Stateful Inspection and Connection Tracking
Stateful packet inspection uses the same fundamental packet screening technique that packet filtering does. In addition, it examines the packet header information from the network layer of the OSI model to the application layer to verify that the packet is part of a legitimate connection and the protocols are behaving as expected.
The stateful packet inspection process is accomplished in the following manner. As packets pass through the firewall, packet header information is examined and fed into a dynamic state table where it is stored. The packets are compared to pre-configured rules or filters and allow or deny decisions are made based on the results of the comparison. The data in the state table is then used to evaluate subsequent packets to verify that they are part of the same connection. In short, stateful packet inspection uses a two step process to determine whether or not packets will be allowed or denied. This method can make decisions based on one or more of the following:
  • Source IP address
  • Destination IP address
  • Protocol type (TCP/UDP)
  • Source port
  • Destination port
  • Connection state
The connection state is derived from information gathered in previous packets. It is an essential factor in making the decision for new communication attempts. Stateful packet inspection compares the packets against the rules or filters and then checks the dynamic state table to verify that the packets are part of a valid, established connection. By having the ability to "remember" the status of a connection, this method of packet screening is better equipped to guard against attacks than standard packet filtering.
Stateful packet inspection solutions offer sophisticated decision-making capabilities, yet they operate faster than other packet screening methods because they require little processing overhead. Allow and deny decisions are made at the lower levels of the OSI model.
Some newer stateful packet inspection firewalls maintain more advanced connection state information. Some are able to reassemble the packets as they pass through the firewall and perform additional processing such as content filtering.
Connection States
  • NEW

    This packet is trying to create a new connection. Unless you're running a server you shouldn't allow these on the input side.
     
  • RELATED

    This packet is related to the existing connection, and is passing in the original direction
    .
     
  • INVALID

    his packet doesn't match any connection
     
  • ESTABLISHED

    This packet is part of an existing connection
As a simple example, to forward across the firewall interfaces packets that are part of a pre-existing connection might look like this:
iptables -A FORWARD -m state -state ESTABLISHED,RELATED -j ACCEPT
Installation and Configuration
  1. Download iptables from netfilter.org, on GENTOO use

    emerge iptables
     
  2. Prepare the Kernel

    cd /usr/src/linux
    make menuconfig
    (Enable Network packet filtering in Networking options)
     
  3. Download Firewall Builder from fwbuilder.org

    With this tool, you can build the basic iptables rules. Here are our basic rules.
    #!/bin/sh

    # Akadia AG, Fichtenweg 10, 3672 Oberdiessbach
    # --------------------------------------------------------------------------
    # File:        firewall.fw
    #
    # Autor:       Martin Zahn, 28.07.2005
    #
    # Purpose:     Configuration file IPTABLES Firewall
    #
    # Location:    /home/zahn/iptables
    #
    # Load Rules:  ./firewall.fw
    # Save Rules:  /etc/init.d/iptables save
    #
    # --------------------------------------------------------------------------
    #

    PATH="/sbin:/usr/sbin:/bin:/usr/bin:${PATH}"
    export PATH

    log() {
      echo "$1"
      test -x "$LOGGER" && $LOGGER -p info "$1"
    }

    va_num=1
    add_addr() {
      addr=$1
      nm=$2
      dev=$3

      type=""
      aadd=""

      L=`$IP -4 link ls $dev | head -n1`
      if test -n "$L"; then
        OIFS=$IFS
        IFS=" /:,<"
        set $L
        type=$4
        IFS=$OIFS

        L=`$IP -4 addr ls $dev to $addr | grep inet | grep -v :`
        if test -n "$L"; then
          OIFS=$IFS
          IFS=" /"
          set $L
          aadd=$2
          IFS=$OIFS
        fi
      fi
      if test -z "$aadd"; then
        if test "$type" = "POINTOPOINT"; then
          $IP -4 addr add $addr dev $dev scope global label $dev:FWB${va_num}
          va_num=`expr $va_num + 1`
        fi
        if test "$type" = "BROADCAST"; then
          $IP -4 addr add $addr/$nm dev $dev brd + scope global label $dev:FWB${va_num}
          va_num=`expr $va_num + 1`
        fi
      fi
    }

    getInterfaceVarName() {
      echo $1 | sed 's/\./_/'
    }

    getaddr() {
      dev=$1
      name=$2
      L=`$IP -4 addr show dev $dev | grep inet | grep -v :`
      test -z "$L" && {
        eval "$name=''"
        return
      }
      OIFS=$IFS
      IFS=" /"
      set $L
      eval "$name=$2"
      IFS=$OIFS
    }

    getinterfaces() {
      NAME=$1
      $IP link show | grep ": $NAME" | while read L; do
        OIFS=$IFS
        IFS=" :"
        set $L
        IFS=$OIFS
        echo $2
      done
    }

    LSMOD="lsmod"
    MODPROBE="modprobe"
    IPTABLES="iptables"
    IPTABLES_RESTORE="iptables-restore"
    IP="ip"
    LOGGER="logger"

    getaddr ppp0  i_ppp0

    log 'Activating firewall script'

    echo "Cleanup iptables Rules"
    $IPTABLES -P OUTPUT  DROP
    $IPTABLES -P INPUT   DROP
    $IPTABLES -P FORWARD DROP
    # $IPTABLES -F
    # $IPTABLES -X

    cat /proc/net/ip_tables_names | while read table; do
      test "X$table" = "Xmangle" && continue
      $IPTABLES -t $table -L -n | while read c chain rest; do
          if test "X$c" = "XChain" ; then
            $IPTABLES -t $table -F $chain
          fi
      done
      $IPTABLES -t $table -X
    done

    # echo "Mainly for PPPoE, VPN and DSL (MTU Fix, activate it if you have)"
    # echo "Problems with large Downloads over PPPoE"
    # $IPTABLES -A OUTPUT -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
    # $IPTABLES -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
    #
    echo "Connection Tracking Rules"
    $IPTABLES -A INPUT   -m state --state ESTABLISHED,RELATED -j ACCEPT
    $IPTABLES -A OUTPUT  -m state --state ESTABLISHED,RELATED -j ACCEPT
    $IPTABLES -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
    #
    # echo "NAT: Masquerade our Traffic"
    # $IPTABLES -t nat -A POSTROUTING -o ppp0  -j MASQUERADE

    echo "Static NAT to IP: 213.3.5.17"
    $IPTABLES -t nat -A POSTROUTING -o ppp0 -j SNAT --to 213.3.5.17


    # echo "Portforwarding: 25 --> 192.168.138.28:25"$IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 25 -j DNAT --to 192.168.138.28:25
    # echo "Portforwarding: 53 --> 192.168.138.28:25"$IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 53 -j DNAT --to 192.168.138.28:53
    $IPTABLES -t nat -A PREROUTING -p udp -i ppp0 --dport 53 -j DNAT --to 192.168.138.28:53


    # echo "Portforwarding: 80,8080,8081 --> 192.168.138.28:80,8080,8081"
    $IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 80 -j DNAT --to 192.168.138.28:80
    $IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 8080 -j DNAT --to 192.168.138.28:8080
    $IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 8081 -j DNAT --to 192.168.138.28:8081


    # echo "Portforwarding: 143 --> 192.168.138.28:143"$IPTABLES -t nat -A PREROUTING -p tcp -i ppp0 --dport 143 -j DNAT --to 192.168.138.28:143#echo "Anti Spoofing Rule"
    $IPTABLES -N ppp0_In_RULE_0
    test -n "$i_ppp0" && $IPTABLES -A INPUT  -i ppp0  -s $i_ppp0  -j ppp0_In_RULE_0
    $IPTABLES -A INPUT  -i ppp0  -s 192.168.138.1  -j ppp0_In_RULE_0
    $IPTABLES -A INPUT  -i ppp0  -s 192.168.138.0/24  -j ppp0_In_RULE_0
    test -n "$i_ppp0" && $IPTABLES -A FORWARD  -i ppp0  -s $i_ppp0  -j ppp0_In_RULE_0
    $IPTABLES -A FORWARD  -i ppp0  -s 192.168.138.1  -j ppp0_In_RULE_0
    $IPTABLES -A FORWARD  -i ppp0  -s 192.168.138.0/24  -j ppp0_In_RULE_0
    $IPTABLES -A ppp0_In_RULE_0   -j LOG  --log-level info --log-prefix "RULE 0 -- DENY "
    $IPTABLES -A ppp0_In_RULE_0   -j DROP

    #echo "Loopback (lo) Rules"
    $IPTABLES -A INPUT  -i lo  -m state --state NEW  -j ACCEPT
    $IPTABLES -A OUTPUT  -o lo  -m state --state NEW  -j ACCEPT

    #
    echo "Allow the following TCP Ports from Aynwhere"

    $IPTABLES -A OUTPUT  -p tcp -m tcp -m multiport --dports 22,80,443,25,143,8080,8081 \
      -m state --state NEW -j ACCEPT
    $IPTABLES -A INPUT   -p tcp -m tcp -m multiport --dports 22,80,443,25,143,8080,8081 \
      -m state --state NEW -j ACCEPT
    $IPTABLES -A FORWARD -p tcp -m tcp -m multiport --dports 22,80,443,25,143,8080,8081 \
      -m state --state NEW -j ACCEPT

    #
    echo "Allow DNS Zone Transfer only from 62.2.210.211"
    $IPTABLES -A OUTPUT  -p tcp -m tcp -d 62.2.210.211 --dport 53 -m state --state NEW -j ACCEPT
    $IPTABLES -A INPUT   -p tcp -m tcp -d 62.2.210.211 --dport 53 -m state --state NEW -j ACCEPT
    $IPTABLES -A FORWARD -p tcp -m tcp -d 62.2.210.211 --dport 53 -m state --state NEW -j ACCEPT
    #
    echo "Allow DNS Queries"
    $IPTABLES -A OUTPUT  -p udp -m udp  --dport 53 -m state --state NEW -j ACCEPT
    $IPTABLES -A INPUT   -p udp -m udp  --dport 53 -m state --state NEW -j ACCEPT
    $IPTABLES -A FORWARD -p udp -m udp  --dport 53 -m state --state NEW -j ACCEPT

    #
    echo "Allow NTP Time to setup the Date/Time from NTP Server"
    $IPTABLES -A OUTPUT  -p udp -m udp --dport 123 -m state --state NEW -j ACCEPT
    $IPTABLES -A INPUT   -p udp -m udp --dport 123 -m state --state NEW -j ACCEPT
    $IPTABLES -A FORWARD -p udp -m udp --dport 123 -m state --state NEW -j ACCEPT

    #
    echo "HSZ Rules"

    $IPTABLES -A INPUT  -s 192.168.138.0/24  -m state --state NEW  -j ACCEPT
    $IPTABLES -A OUTPUT  -s 192.168.138.0/24  -m state --state NEW  -j ACCEPT
    $IPTABLES -A FORWARD  -s 192.168.138.0/24  -m state --state NEW  -j ACCEPT

    #
    echo "Logging Rules"$IPTABLES -N RULE_2
    $IPTABLES -A OUTPUT  -j RULE_2
    $IPTABLES -A INPUT  -j RULE_2
    $IPTABLES -A FORWARD  -j RULE_2
    $IPTABLES -A RULE_2  -j LOG  --log-level info --log-prefix "RULE 2 -- DENY "
    $IPTABLES -A RULE_2  -j DROP
    #
    echo "Activate Routing"
    echo 1 > /proc/sys/net/ipv4/ip_forward
     
  4. Load and Save the Rules

    ./firewall.fw
    /etc/init.d/iptables save
    The iptables rules are saved and automatically loaded when the machine is booting the next time. The location of the saved rules are defined in/etc/conf.d/iptables (/var/lib/iptables/rules-save) for GENTOO linux.
Useful iptables Commands
iptables -L          (List Rules)
iptables -t nat -L   (List NAT Rules)

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
DNAT       tcp  --  anywhere             anywhere            tcp dpt:smtp to:192.168.138.28:25
DNAT       tcp  --  anywhere             anywhere            tcp dpt:domain to:192.168.138.20:53
DNAT       udp  --  anywhere             anywhere            udp dpt:domain to:192.168.138.20:53
DNAT       tcp  --  anywhere             anywhere            tcp dpt:www to:192.168.138.21:80

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
SNAT       all  --  anywhere             anywhere            to:213.3.5.17

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
iptables -F    (Delete all rules)
iptables -X    (Delete all userdefined chains)

Source: www.akadia.com.
Tăng tính bảo mật dịch vụ (SSH) cho máy chủ Linux với Denyhosts

Tăng tính bảo mật dịch vụ (SSH) cho máy chủ Linux với Denyhosts

  1. Download và tham khảo cách cài đặt tại _http://denyhosts.sourceforge.net_
  2. Kết hợp với _http://tuyenninhduan.blogspot.com/2010/06/meo-va-thu-thuat-bao-mat-ssh-nang-cao.html để máy chủ được bảo mật hơn
  3. Vài thông số cấu hình
[username@host ~]$ grep -v "#" /usr/share/denyhosts/denyhosts.cfg
SECURE_LOG = /var/log/secure
HOSTS_DENY = /etc/hosts.deny
PURGE_DENY = 10m
BLOCK_SERVICE = sshd
DENY_THRESHOLD_INVALID = 5
DENY_THRESHOLD_VALID = 10
DENY_THRESHOLD_ROOT = 1
DENY_THRESHOLD_RESTRICTED = 1
WORK_DIR = /usr/share/denyhosts/data
SUSPICIOUS_LOGIN_REPORT_ALLOWED_HOSTS=YES
HOSTNAME_LOOKUP=YES
LOCK_FILE = /var/lock/subsys/denyhosts
ADMIN_EMAIL =
SMTP_HOST = localhost
SMTP_PORT = 25
SMTP_FROM = DenyHosts
SMTP_SUBJECT = DenyHosts Report
AGE_RESET_VALID=5d
AGE_RESET_ROOT=25d
AGE_RESET_RESTRICTED=25d
AGE_RESET_INVALID=10d
DAEMON_LOG = /var/log/denyhosts
DAEMON_SLEEP = 30s
DAEMON_PURGE = 1h
Mẹo và thủ thuật bảo mật SSH nâng cao

Mẹo và thủ thuật bảo mật SSH nâng cao

File cấu hình server SSH được đặt trong thư mục /etc/ssh/sshd_conf. Bạn cần khởi động lại dịch vụ SSH sau mỗi lần thay đổi để các thay đổi đó được thực thi.

Thay đổi cổng SSH

Mặc định, SSH tuân theo các kết nối đến trên cổng 22. Kẻ tấn công thường sử dụng phần mềm quét cổng xem liệu các host (máy trạm) có sử dụng dịch vụ SSH không. Thay đổi cổng SSH lên cao hơn 1024 là một lựa chọn khôn ngoan, vì hầu hết mọi chương trình quét cổng (gồm cả nmap) mặc định đều rà soát được các cổng cao.

Mở file /etc/ssh/sshd_config và tìm dòng có ghi:

Port 22

Thay đổi số cổng và khởi động lại dịch vụ SSH:

/etc/init.d/ssh restart

Chỉ cho phép sử dụng giao thức SSH 2

Có hai loại giao thức SSH. Nếu chỉ dùng giao thức SSH 2 thì sẽ an toàn hơn nhiều vì SSH 1 thường gặp phải vấn đề bảo mật với kiểu tấn công man-in-the-middle và insertion. Mở file /etc/ssh/sshd_config và tìm dòng sau:

Protocol 2,1

Thay đổi dòng thành protocol 2.

Chỉ cho phép một số đối tượng người dùng đăng nhập qua SSH

Bạn không nên cho phép người dùng root đăng nhập qua SSH, vì điều này gây nên mối đe doạ bảo mật lớn mà không cần thiết. Nếu một kẻ tấn công nào đó thu được đặc quyền root khi đăng nhập vào máy, khả năng phá hoại có thể gấp mấy lần người dùng thông thường. Bạn nên cấu hình server SSH không cho phép người dùng root đăng nhập. Đầu tiên, tìm dòng ghi:

PermitRootLogin yes

Thay đổi yes thành no và khởi động lại dịch vụ. Sau đó bạn có thể đăng nhập lại hệ thống với bất kỳ vai trò người dùng xác định nào đó và chuyển sang người dùng root nếu muốn trở thành siêu người dùng.

Sẽ khôn ngoan hơn khi tạo một user cục bộ giả hoàn toàn không có đặc quyền gì trên hệ thống và dùng tên user đó để đăng nhập SSH. Sử dụng cách thức này sẽ giúp máy tính không bị hại dù tài khoản người dùng có bị xâm phạm. Khi tạo người dùng này, hãy chắc chắn nó phải nằm trong nhóm wheel để bạn có thể chuyển sang nhóm superuser (siêu người dùng) nếu cần.

Nếu muốn tạo danh sách một số đối tượng người dùng được phép đăng nhập vào SSH, bạn có thể mô tả chúng trong file sshd_config. Ví dụ, nếu muốn cho phép người dùng anze, dasa, kimy đăng nhập qua SSH, ở cuối file sshd_config, thêm vào một dòng như sau:

AllowUsers anze dasa kimy

Tạo banner SSH tuỳ biến

Nếu muốn mời một người dùng kết nối tới dịch vụ SSH để xem một thư nào đó, bạn có thể tạo banner SSH tuỳ biến. Thực hiện đơn giản bằng cách tạo một file text (trong ví dụ là file etc/ssh-banner.txt) và đặt bất kỳ kiểu thư text nào bạn có vào trong đó. Ví dụ:

*****************************************************************
*This is a private SSH service. You are not supposed to be here.*
*Please leave immediately. *
*****************************************************************

Khi muốn chỉnh sửa hoặc ghi file, trong sshd_conf, tìm dòng ghi:

#Banner /etc/issue.net

Không cần bình luận về dòng trên mà hãy thay đổi đường dẫn tới file text banner SSH tuỳ biến của bạn.

Sử dụng cơ chế thẩm định khoá công cộng DSA

Thay vì sử dụng tên và mật khẩu khi đăng nhập vào SSH, bạn có thể dùng cơ chế thẩm định khoá công cộng DSA. Chú ý rằng bạn có thể sử dụng username, password và khoá DSA cùng một lúc. Sử dụng cơ chế thẩm định khoá công cộng DSA cho phép hệ thống ngăn chặn được kiểu tấn công theo sách vở, vì bạn có thể đăng nhập vào dịch vụ SSH mà không cần dùng đến tên và mật khẩu. Thay vào đó, bạn cần một cặp khoá DSA: một khoá chung (public) và một khoá riêng (private). Khoá riêng được giữ trên máy của bạn, còn khoá chung được đưa lên server. Khi muốn đăng nhập vào một phiên SSH, server sẽ kiểm tra khoá. Nếu tất cả thông số đều khớp, bạn được đưa vào hệ thống. Nếu khoá không khớp, kết nối bị ngắt.

Ở ví dụ dưới đây, máy riêng sẽ kết nối tới máy chủ được đặt tên là station1 và máy chủ là server1. Trên cả hai máy đều có cùng một thư mục chủ (home folder). Chú ý là kết nối sẽ không hoạt động nếu thư mục chủ trên client và server khác nhau. Đầu tiên, tạo một cặp khoá trên máy riêng với lệnh ~$ ssh-keygen -t dsa. Bạn sẽ được nhắc cụm mật khẩu cho khoá riêng, nhưng hãy để trống, chúng ta chưa quan tâm đến phương thức này vội. Một cặp khoá được tạo: khoá riêng nằm trong ~/.ssh/id_dsa và khoá chung được đặt tại .ssh/id_dsa.pub.

Tiếp theo, copy nội dung ~/.ssh/id_dsa.pub to server1 vào file ~/.ssh/authorized_keys. Nội dung trong ~/.ssh/id_dsa.pub có dạng:

~$ cat .ssh/id_dsa.pub
ssh-dss AAAAB3NzaC1kc3MAAACBAM7K7vkK5C90RsvOhiHDUROvYbNgr7YEqtrdfFCUVwMWcJYDusNG
AIC0oZkBWLnmDu+y6ZOjNPOTtPnpEX0kRoH79maX8NZbBD4aUV91lbG7z604ZTdrLZVSFhCI/Fm4yROH
Ge0FO7FV4lGCUIlqa55+QP9Vvco7qyBdIpDuNV0LAAAAFQC/9ILjqII7nM7aKxIBPDrQwKNyPQAAAIEA
q+OJC8+OYIOeXcW8qcB6LDIBXJV0UT0rrUtFVo1BN39cAWz5puFe7eplmr6t7Ljl7JdkfEA5De0k3WDs
9/rD1tJ6UfqSRc2qPzbn0p0j89LPIjdMMSISQqaKO4m2fO2VJcgCWvsghIoD0AMRC7ngIe6btaNIhBbq
ri10RGL5gh4AAACAJj1/rV7iktOYuVyqV3BAz3JHoaf+H/dUDtX+wuTuJpl+tfDf61rbWOqrARuHFRF0
Tu/Rx4oOZzadLQovafqrDnU/No0Zge+WVXdd4ol1YmUlRkqp8vc20ws5mLVP34fST1amc0YNeBp28EQi
0xPEFUD0IXzZtXtHVLziA1/NuzY= anze@station1.example.com

Nếu file ~/.ssh/authorized_keys đã tồn tại, gắn thêm nội dung trong ~/.ssh/id_dsa.pub vào file ~/.ssh/authorized_keys trên server1. Bạn chỉ cần thực hiện một việc là thiết lập chính xác đặc quyền trong file ~/.ssh/authorized_keys trên server1:

~$ chmod 600 ~/.ssh/authorized_keys

Bây giờ cấu hình file sshd_conf để sử dụng cơ chế thẩm định khoá DSA. Hãy chắc chắn rằng bạn có ba dòng không chú thích sau:

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys

Khởi động lại dịch vụ. Nếu mọi thứ đã được cấu hình chính xác, bạn đã có thể sử dụng SSH cho server và đặt trực tiếp nó vào thư mục chủ mà không cần bất kỳ tương tác nào khác.

Nếu muốn chỉ sử dụng duy nhất một cơ chế thẩm định DSA, không cần chú thích hay thay đổi dòng PasswordAuthentication trong file sshd_config từ yes thành no:

PasswordAuthentication no

Nếu ai đó cố gắng kết nối tới dịch vụ SSH mà không có khoá chung trên server, anh ta sẽ bị từ chối và thậm chí không được đưa nền đăng nhập ra với thông báo lỗi:

Permission denied (publickey).

Sử dụng các hàm bao TCP để cho phép chỉ một số host được kết nối

Phương thức trên sẽ rất hữu ích nều bạn muốn giới hạn số host trên mạng có thể kết nối tới dịch vụ SSH. Nhưng nó không thể sử dụng hoặc kết hợp được với cấu hình các bảng IP (iptable). Thay vào đó, bạn có thể dùng các hàm bao TCP, cụ thể là sshd TCP. Bạn có thể đưa ra quy tắc chỉ cho phép một số host nhất định trên mạng con cục bộ (local subnet) 192.168.1.0/24 và host từ xa 193.180.177.13 kết nối tới dịch vụ SSH.

Các hàm bao TCP mặc định đầu tiên sẽ xem trong file /etc/hosts.deny danh sách các host bị từ chối kết nối tới dịch vụ. Tiếp theo là file /etc/hosts để xem liệu có quy tắc nào cho phép một số host kết nối tới một dịch vụ đặc biệt nào đó không. Ví dụ, tôi sẽ tạo một quy tắc như vậy trong tư mục /etc/hosts.deny:

sshd: ALL

Quy tắc trên có nghĩa là, mặc định tất cả các host đều bị cấm truy cập dịch vụ SSH. Điều này là cần thiết, vì nếu không tất cả các host ở đây đều có quyền truy cập dịch vụ SSH. Do hàm bao TCP đầu tiên sẽ xem xét trong file hosts.deny, nếu không có quy tắc nào liên quan đến ngăn chặn sử dụng dịch vụ SSH, bất kỳ host nào cũng có thể đến nôi đến nó. Tiếp theo, tạo một quy tắc trong /etc/hosts để cho phép chỉ một số host cụ thể (như được định nghĩa ở trên) sử dụng dịch vụ SSH:

sshd: 192.168.1 193.180.177.13

Bây giờ, chỉ có các host trên mạng 192.168.1.0/24 và host 193.180.177.13 mới có quyền truy cập dịch vụ SSH. Tất cả host khác đều bị ngắt kết nối trước khi được đăng nhập và nhận một thông báo lỗi như sau:

ssh_exchange_identification: Connection closed by remote host

Sử dụng iptables để giới hạn số lượng host được kết nối

Một lựa chọn khác ngoài các hàm bao TCP là giới hạn truy cập SSH với iptables (các bảng địa chỉ IP). Song, bạn có thể sử dụng kết hợp cả hai phương thức này cùng một lúc. Dưới đây là một ví dụ đơn giản về cách cho phép một số host nhất định kết nối tới SSH:

~# iptables -A INPUT -p tcp -m state --state NEW --source 193.180.177.13 --dport 22 -j ACCEPT

Và để chắc chắn rằng không có host nào khác được truy cập dịch vụ SSH:

~# iptables -A INPUT -p tcp --dport 22 -j DROP

Ghi lại một số quy tắc mới và hoàn chỉnh công việc.

Một số mẹo thời gian SSH

Bạn có thể dùng các tham số iptables khác để giới hạn kết nối tới dịch vụ SSH trong một khoảng thời gian nhất định. Kiểu thời gian có thể là giây, phút, giờ, hoặc ngày (/second, /minute, /hour, /day ), như ví dụ dưới đây.

Ở ví dụ đầu, nếu người dùng nhập mật khẩu sai, truy cập vào dịch vụ SSH sẽ bị khoá trong một phút. Và sau đó người dùng chỉ được phép gõ thông tin đăng nhập vào sau từng phút:

~# iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -m limit --limit 1/minute --limit-burst 1 -j ACCEPT
~# iptables -A INPUT -p tcp -m state --syn --state NEW --dport 22 -j DROP

Trong ví dụ thứ hai, iptables được thiết lập chỉ cho phép host 193.180.177.13 kết nối tới dịch vụ SSH. Sau ba lần đăng nhập thất bại, iptables chỉ cho phép host đăng nhập lại sau từng phút:

~# iptables -A INPUT -p tcp -s 193.180.177.13 -m state --syn --state NEW --dport 22 -m limit --limit 1/minute --limit-burst 1 -j ACCEPT
~# iptables -A INPUT -p tcp -s 193.180.177.13 -m state --syn --state NEW --dport 22 -j DROP

Kết luận

Các thành phần này không khó cầu hình, nhưng chúng là những kỹ thuật rất mạnh trong chế độ bảo mật dịch vụ SSH. Bỏ ra chút thời gian đầu tư, bạn sẽ có được giấc ngủ ngon .

Từ Internet
7 lệnh hữu dụng cho mạng Linux

7 lệnh hữu dụng cho mạng Linux

ifconfig cho giao diện cơ bản và cấu hình IP

Công cụ ifconfig (được lấy từ hai chữ interface configurator) tuy cung cấp ít chức năng nhưng là các chức năng rất quan trọng. Nó cho phép bạn có thể bật, tắt adapter mạng, gán địa chỉ IP và các thông tin netmask chi tiết. Đây là một số lệnh điển hình nhất:

Xem cấu hình hiện hành của các giao diện mạng, gồm có cả tên giao diện:

ifconfig

Bật hoặc tắt một adapter:

ifconfig

Gán một địa chỉ IP cho một adapter

ifconfig

Gán địa chỉ IP thứ hai cho một adapter:

ifconfig

Ví dụ: ifconfig eth0:0 192.168.1.101

ethtool quản lý các thiết lập ethernet card

Ethtool cho phép bạn xem và thay đổi nhiều thiết lập khác nhau cho các adapter ethernet (adapter không có card Wi-Fi). Bạn có thể quản lý nhiều thiết lập nâng cao khác, gồm có tx/rx, kiểm tra tổng và các thiết lập wake-on-LAN. Mặc dù vậy, đây là một số lệnh cơ bản hơn mà bạn cần phải quan tâm:

Hiển thị các thông tin driver cho một adapter mạng nào đó, rất quan trọng cho việc kiểm tra khả năng tương thích của phần mềm:

ethtool -i

Khởi tạo hành động adapter, thường là nhấp nháy các đèn LED trên adapter, để giúp bạn có thể nhận ra giữa các adapter và tên giao diện:

ethtool -p

Hiển thị thống kê mạng:

ethtool -S

Thiết lập tốc độ kết nối của adapter theo Mbps:

ethtool speed <10|100|1000>

iwconfig cho cấu hình không dây

Công cụ iwconfig cũng giống như ifconfig và ethtool cho card không dây. Bạn có thể xem và thiết lập các chi tiết cho mạng Wi-Fi, chẳng hạn như SSID, kênh và sự mã hóa. Cũng có nhiều thiết lập nâng cao khác bạn có thể xem và thay đổi, gồm có nhận độ nhạy, /CTS, fragmentation và các entry. Đây là một số lệnh mà bạn cần phải thử:

Hiển thị các thiết lập không dây cho giao diện, gồm có tên giao diện mà bạn cần cho các lệnh khác:

iwconfig

Thiết lập ESSID (Extended Service Set Identifier) hoặc tên mạng:

iwconfig essid

Ví dụ: iwconfig "my network"

Ví dụ: iwconfig any

Thiết lập kênh không dây của radio (1-11):

iwconfig

Đầu vào khóa mã hóa WEP (WPA/WPA2 vẫn chưa được hỗ trợ):

iwconfig eth0 key

Chỉ cho phép adapter kết nối đến một AP có địa chỉ MAC được chỉ định:

iwconfig ap

Ví dụ: iwconfig eth0 ap 00:60:1D:01:23:45

Thiết lập năng lượng truyền tải radio, nếu được hỗ trợ bởi card không dây, mặc định trong định dạng dBm hoặc mW khi được chỉ định:

iwconfig txpower

Ví dụ: iwconfig eth0 txpower 15

Ví dụ: iwconfig eth0 txpower 30mW

tcpdump cho việc “đánh hơi” các gói mạng

Đây không phải là một công cụ đơn giản mà nó còn là một bộ đánh hơi hay phân tích mạng. Công cụ này có thể capture các gói dữ liệu được truyền tải qua giao diện và trên mạng. Bạn có thể thanh tra các gói dữ liệu thô và xem lại các thống kê. Công cụ thường được sử dụng bởi các chương trình GUI khác, tuy nhiên cũng có thể rất hữu dụng trong một terminal. Đây là một số tùy chọn lệnh mà bạn có thể thực hiện với nó:

* -i: Chỉ định giao diện để capture, chẳng hạn như eth0 hoặc ath0.
* -n: Ngừng việc thay thế các địa chỉ IP bằng hostname.
* -nn: Ngừng việc phân giải hostname hoặc tên cổng.
* -s : Số byte tối đa được hiển thị cho mỗi gói. Mặc định là 68. Sử dụng 0 để hiển thị toàn bộ các gói.
* v, -vv, và -vvv: Các thông tin chi tiết được in cùng với các gói, chẳng hạn như các tùy chọn và chiều dài tổng thể trong một gói IP, các gói SMB được giải mã và các chi tiết telnet.
* -x: Hiển thị nội dung gói theo định dạng HEX
* -X: In nội dung các gói dữ liệu dưới định dạng ASCII

Ping, phát hiện mạng của bạn

Công cụ Ping giống như những gì Microsoft cung cấp trong Windows. Mặc dù vậy, các kiểu tùy chọn và tên có thể khác nhau. Trong Linux, mặc định sẽ ping liên tục.

Thực hiện ping một địa chỉ IP hoặc một host/domain name:

ping

Để stop hành động ping, nhấn Ctrl + C.

Đây là một số tùy chọn bạn có thể sử dụng thêm:

* -c: Đến hoặc đánh số gói để gửi đi
* -i: Đợi một khoảng thời gian; số giây nào đó giữa các gói
* -s: Kích thước gói của các ping; mặc định là 56 (64 với ICMP)
* -w: Đợi theo dây hoặc số lượng giây để thực hiện ping

Netstat cho việc xem lại thống kê mạng

Công cụ Netstat (hoặc thống kê mạng) có thể hiển thị các thông tin chi tiết về các kết nối mạng, thống kê giao diện, bảng định tuyến, các kết nối giả mạo. Đây là một số lệnh bạn cần quan tâm:
Xem danh sách các khe đang mở:

netstat

Hiển thị một bảng chứa tất cả các giao diện mạng:

netstat -i

Hiển thị thống kê tổng kết cho mỗi giao thức:

netstat -s

Hostname cho phép bạn xem và thay đổi hostname của mình

Nếu là một quản trị viên, bạn sẽ biết được hostname là gì. Với những người còn lại: một hostname sẽ giúp họ nhận ra các thiết bị mạng theo cách thân thiện người dùng thay vì chỉ là một địa chỉ IP toàn con số. Phân phối Linux thường có một công cụ đơn giản mang tên hostname để xem và thay đổi tạm thời hostname của bạn.

Xem thiết lập hostname hiện hành:

hostname

Thay đổi tạm thời một hostname (cho tới khi khởi động lại):

hostname

Để thay đổi vĩnh viễn hostname, bạn cần phải thực hiện edit các file /etc/hostname or /etc/sysconfig/network.

Văn Linh (Theo Linuxplanet) - QTM
Cài đặt và cấu hình Web Server trên LINUX

Cài đặt và cấu hình Web Server trên LINUX

-= Cài đặt và cấu hình Web Server =-
1. Cài đặt Web Server
Với Linux (sử dụng phiên bản CentOS), chúng ta có thể chọn gói mã nguồn như httpd-2.2.3.tar.gz. Đây là gói miễn phí, chúng ta hoàn toàn có thể download được trên mạng:
• Nếu sử dụng gói .gz thì dùng lệnh: tar xvzf httpd-***.tar.gz
• Vào thư mục vừa giải mã, sau đó sử dụng các lệnh ./configure | make | make install để cài đặt.
• Còn nếu cài đặt từ những gói rpm thì gõ lệnh: rpm -ivh httpd-***.rpm
• Bây giờ, chúng ta có thể chạy Web Server nếu chúng ta muốn. Tuy nhiên, vẫn có khi gặp trường hợp không thể khởi động được như: lỗi vì đã có phần mềm nào đó chạy trên port mà Web Server ta sẽ chạy (80). Điều này có thể khắc phục được một cách dễ dàng, bằng cách tắt chương trình chạy trên port đó đi. Và bây iờ khởi động lại là có thể chạy được.
• Để start – stop – restart webserver: /etc/init.d/httpd start|stop|restart hoặc dùng lệnh:
#chkconfig httpd on
#service httpd start|stop|restart
• Tuy nhiên, để có thể hiểu cũng như vận hành theo đúng ý muốn của chúng ta thì cần phải hiểu và cũng như phải tận tay cấu hình nó.

2. Cấu hình Web Server:
Các tập tin và thư mục cấu của Apache:
• /etc/httpd/conf: thư mục lưu giữ các tập tin cấu hình như httpd.conf.
• /etc/httpd/modules: lưu giữ các module của Web Server.
• /etc/httpd/logs: lưu các tập tin log của Apache.
• /var/www/html: lưu các trang web.
• /var/www/cgi-bin: lưu các script sử dụng cho các trang web
Tập tin cấu hình Apache được tạo thành từ nhiều chỉ dẫn (directive) khác nhau.Mỗi dòng hoặc mỗi một directive và phục vụ cho một cấu hình riêng biệt. Có những directive có ảnh hưởng với nhau. Những dòng bắt đầu bằng dấu # là những dòng chú thích. Sau đây là những directive quan trọng khi cấu hình Web Server.

ServerName:
Cú pháp: ServerName port
Trong đó, hostname là tên máy tính của Server. Nó được dùng trong việc tạo ra những URL chuyển tiếp (direction URL). Nếu không chỉ ra, server sẽ cố gắng suyluận từ địa chỉ IP của nó. Tuy nhiên, điều này có thể không tin cậy hoặc không trả ra tên máy tính đúng.
Ví dụ: ServerName www.linuxcentos.org

ServerAdmin: địa chỉ email của người quản trị hệ thống
Cú pháp: ServerAdmin <địa chỉ email>
Ví dụ: ServerAdmin webadmin@linuxcentos.org

ServerType: quy định cách nạp chương trình. Có 2 cách:
• inetd: chạy từ các init level.
• standalone: chạy từ hệ thống.
Cú pháp: ServerType
Ví dụ: ServerType standalone

DocumentRoot: cấu hình thư mục góc, lưu trữ nội dung của Website. Web Server sẽ lấy những tập tin trong thư mục này phục vụ cho yêu cầu của client.
Cú pháp: DocumentRoot <đường dẫn thư mục>
Ví dụ: DocumentRoot /usr/web

ServerRoot: Vị trí cài đặt chương trình Apache.
Cú pháp: ServerRoot
Ví dụ: ServerRoot /user/local/apache

ErrorLog: chỉ ra tập tin để server ghi vào bất kỳ những lỗi nào mà nó gặp phải.
Cú pháp: ErrorLog
Ví dụ: ErrorLog logs/error_log

DirectoryIndex: các tập tin mặc định được truy vấn khi truy cập trang Web.
Cú pháp: DirectoryIndex
Ví dụ: DirectoryIndex index.html

MaxClients: Quy định số yêu cầu kết nối từ các client đến server.
Cú pháp: MaxClients
Ví dụ MaxClients 256

Listen: quy định địa chỉ IP hoặc cổng mà Apache nhận kết nối từ Client.
Cú pháp: Listen
Ví dụ: Listen 80

BindAddress: quy định địa chỉ card mạng để chạy Apache trên Server.
Cú pháp: BindAddress
Sử dụng dấu “*” để có thể sử dụng tất cả các địa chỉ trên máy.
Ví dụ: BindAddress 192.168.7.8

TimeOut: quy định thời gian sống của một kết nối (được tính bằng giây).
Cú pháp: TimeOut
Ví dụ: TimeOut 300

KeepAlive: cho phép hoặc không cho phép client gửi được nhiều yêu cầu dựa trên một kết nối đến với Web Server.
Cú pháp: KeepAlive
Ví dụ: KeepAlive On

MaxKeepAliveRequests: số Request tối đa trên một kết nối (nếu cho phép nhiều Request trên một kết nối).
Cú pháp: MaxKeepAliveRequests
Ví dụ: MaxKeepAliveRequests 100

KeepAliveTimeout: thời gian chờ một Request kế tiếp từ cùng một client trên cùng một kết nối (được tính bằng giây).
Cú pháp: KeepAliveTimeout
Ví dụ: KeepAliveTimeout 15

Alias: ánh xạ đường dẫn cục bộ (không nằm trong DocumentRoot) thành tên đường dẫn địa chỉ URL.
Cú pháp: Alias <đường dẫn http><đường dẫn cục bộ>
Ví dụ: Alias /doc /usr/share/doc
Khi truy cập http://www.linuxcentos.org/doc, nó sẽ vào /usr/share/doc.

Để giới hạn việc truy cập của người dùng ta có thể kết hợp với Directory directive.
Ví dụ: Alias /doc /usr/share/doc
AuthType Basic #kiểu authentication sẽ sử dụng là Basic
AuthName intranet #đặt tên cho sự chứng thực là intranet
AuthUserFile /etc/httpd/passwd #vị trí của tập tin password
Require user hongthai minhtri #user cho phép truy cập tài nguyên
Allow from internal.linuxcentos.org #cho phép truy cập từ đchỉ này

UserDir: cho phép người dùng tạo Home page của user trên Web Server.
Cú pháp:

UserDir Disables ## để thực thi cơ chế enable UserDir
UserDir www ## Khai báo thư mục chứa Website của user
…

Trong thư mục Home Directory của người dùng tạo thư mục www.
Ví dụ:
/home/adminloc Khi đó, cú pháp truy cập từ Web Browser có dạng:
http://www.linuxcentos.org/~ tức trong trường hợp này là http://www.linuxcentos.org/~adminloc. Khi người dùng có gắng truy cập đến thư mục của mình, có thể gặp một message lỗi “Forbidden”. Điều này có thể là quyền truy cập đến home directory của người dùng bị giới hạn. Như vậy để khắc phục lỗi trên, chúng ta cần giới hạn lại quyền truy cập home directory của người dùng với những câu lệnh như sau:
chown adminloc /home/adminloc/home/adminloc/www
chmod 750 /home/adminloc/home/adminloc/www

VirtualHost: là tính năng của Apache, giúp ta duy trì nhiều hơn một web server trên một máy tính. Nhiều tên cùng chia sẻ một địa chỉ IP gọi là named-based virtual hosting và sử dụng những địa chỉ IP khác nhau cho từng domain gọi là IP-based
virtual hosting.
• IP-based Virtual Host: Virtual Host dựa trên IP yêu cầu những server phải có một địa chỉ IP khác nhau cho mỗi virtual host dựa trên IP. Như vậy, một máy tính phải có nhiều interface hay sử dụng cơ chế virtual interface mà những hệ điều hành sau hỗi trợ. Nếu máy của chúng ta có một địa chỉ IP, 192.168.7.8, chúng ta có thể cấu hình một địa chỉ IP khác trên cùng một card mạng như sau:

ifconfig eth0:1 192.168.7.9 netmask 255.255.255.0 up

Sau đó, chúng ta mô tả thông tin cấu hình trong file httpd.conf
; VirtualHost default
...
DocumentRoot/tmp
ServerName www.domain
…


;VirtualHost cho site 1
…
DocumentRoot/home/www/site1
ServerName www1.domain


;VirtualHost cho site 2
…
DocumentRoot/home/www/site2
ServerName www2.domain
…

• Name-based Virtual Host: IP-based Virtual Hosts dựa vào địa chỉ IP để quyết định Virtual Host nào đúng để truy cập. Vì thế, chúng ta cần phải có địa chỉ khác nhau cho mỗi Virtual Host. Với Named-based Virtual Host, server dựa vào HTTP header của client để biết được hostname. Sử dụng kỹ thuật này, một địa chỉ IP có thể có nhiều tên máy tính khác nhau. Named-based Virtual Host rất đơn giản, chúng ta chỉ cần cấu hình DNS sao cho nó phân giải mỗi tên máy đúng với một địa chỉ IP và sau đó cấu hình Apache để tổ chức những web server cho những miền khác nhau.

Linux Command

Linux Command

a
alias Create an alias
apropos Search Help manual pages (man -k)
apt-get Search for and install software packages (Debian)
aspell Spell Checker
awk Find and Replace text, database sort/validate/index
b
bash GNU Bourne-Again SHell
bc Arbitrary precision calculator language
bg Send to background
break Exit from a loop
builtin Run a shell builtin
bzip2 Compress or decompress named file(s)
c
cal Display a calendar
case Conditionally perform a command
cat Display the contents of a file
cd Change Directory
cfdisk Partition table manipulator for Linux
chgrp Change group ownership
chmod Change access permissions
chown Change file owner and group
chroot Run a command with a different root directory
chkconfig System services (runlevel)
cksum Print CRC checksum and byte counts
clear Clear terminal screen
cmp Compare two files
comm Compare two sorted files line by line
command Run a command - ignoring shell functions
continue Resume the next iteration of a loop
cp Copy one or more files to another location
cron Daemon to execute scheduled commands
crontab Schedule a command to run at a later time
csplit Split a file into context-determined pieces
cut Divide a file into several parts
d
date Display or change the date & time
dc Desk Calculator
dd Convert and copy a file, write disk headers, boot records
ddrescue Data recovery tool
declare Declare variables and give them attributes
df Display free disk space
diff Display the differences between two files
diff3 Show differences among three files
dig DNS lookup
dir Briefly list directory contents
dircolors Colour setup for `ls'
dirname Convert a full pathname to just a path
dirs Display list of remembered directories
dmesg Print kernel & driver messages
du Estimate file space usage
e
echo Display message on screen
egrep Search file(s) for lines that match an extended expression
eject Eject removable media
enable Enable and disable builtin shell commands
env Environment variables
ethtool Ethernet card settings
eval Evaluate several commands/arguments
exec Execute a command
exit Exit the shell
expect Automate arbitrary applications accessed over a terminal
expand Convert tabs to spaces
export Set an environment variable
expr Evaluate expressions
f
false Do nothing, unsuccessfully
fdformat Low-level format a floppy disk
fdisk Partition table manipulator for Linux
fg Send job to foreground
fgrep Search file(s) for lines that match a fixed string
file Determine file type
find Search for files that meet a desired criteria
fmt Reformat paragraph text
fold Wrap text to fit a specified width.
for Expand words, and execute commands
format Format disks or tapes
free Display memory usage
fsck File system consistency check and repair
ftp File Transfer Protocol
function Define Function Macros
fuser Identify/kill the process that is accessing a file
g
gawk Find and Replace text within file(s)
getopts Parse positional parameters
grep Search file(s) for lines that match a given pattern
groups Print group names a user is in
gzip Compress or decompress named file(s)
h
hash Remember the full pathname of a name argument
head Output the first part of file(s)
history Command History
hostname Print or set system name
i
id Print user and group id's
if Conditionally perform a command
ifconfig Configure a network interface
ifdown Stop a network interface
ifup Start a network interface up
import Capture an X server screen and save the image to file
install Copy files and set attributes
j
join Join lines on a common field
k
kill Stop a process from running
killall Kill processes by name
l
less Display output one screen at a time
let Perform arithmetic on shell variables
ln Make links between files
local Create variables
locate Find files
logname Print current login name
logout Exit a login shell
look Display lines beginning with a given string
lpc Line printer control program
lpr Off line print
lprint Print a file
lprintd Abort a print job
lprintq List the print queue
lprm Remove jobs from the print queue
ls List information about file(s)
lsof List open files
m
make Recompile a group of programs
man Help manual
mkdir Create new folder(s)
mkfifo Make FIFOs (named pipes)
mkisofs Create an hybrid ISO9660/JOLIET/HFS filesystem
mknod Make block or character special files
more Display output one screen at a time
mount Mount a file system
mtools Manipulate MS-DOS files
mv Move or rename files or directories
mmv Mass Move and rename (files)
n
netstat Networking information
nice Set the priority of a command or job
nl Number lines and write files
nohup Run a command immune to hangups
nslookup Query Internet name servers interactively
o
open Open a file in its default application
op Operator access
p
passwd Modify a user password
paste Merge lines of files
pathchk Check file name portability
ping Test a network connection
popd Restore the previous value of the current directory
pr Prepare files for printing
printcap Printer capability database
printenv Print environment variables
printf Format and print data
ps Process status
pushd Save and then change the current directory
pwd Print Working Directory
q
quota Display disk usage and limits
quotacheck Scan a file system for disk usage
quotactl Set disk quotas
r
ram ram disk device
rcp Copy files between two machines
read read a line from standard input
readonly Mark variables/functions as readonly
reboot Reboot the system
renice Alter priority of running processes
remsync Synchronize remote files via email
return Exit a shell function
rev Reverse lines of a file
rm Remove files
rmdir Remove folder(s)
rsync Remote file copy (Synchronize file trees)
s
screen Multiplex terminal, run remote shells via ssh
scp Secure copy (remote file copy)
sdiff Merge two files interactively
sed Stream Editor
select Accept keyboard input
seq Print numeric sequences
set Manipulate shell variables and functions
sftp Secure File Transfer Program
shift Shift positional parameters
shopt Shell Options
shutdown Shutdown or restart linux
sleep Delay for a specified time
slocate Find files
sort Sort text files
source Run commands from a file `.'
split Split a file into fixed-size pieces
ssh Secure Shell client (remote login program)
strace Trace system calls and signals
su Substitute user identity
sudo Execute a command as another user
sum Print a checksum for a file
symlink Make a new name for a file
sync Synchronize data on disk with memory
t
tail Output the last part of files
tar Tape ARchiver
tee Redirect output to multiple files
test Evaluate a conditional expression
time Measure Program running time
times User and system times
touch Change file timestamps
top List processes running on the system
traceroute Trace Route to Host
trap Run a command when a signal is set(bourne)
tr Translate, squeeze, and/or delete characters
true Do nothing, successfully
tsort Topological sort
tty Print filename of terminal on stdin
type Describe a command
u
ulimit Limit user resources
umask Users file creation mask
umount Unmount a device
unalias Remove an alias
uname Print system information
unexpand Convert spaces to tabs
uniq Uniquify files
units Convert units from one scale to another
unset Remove variable or function names
unshar Unpack shell archive scripts
until Execute commands (until error)
useradd Create new user account
usermod Modify user account
users List users currently logged in
uuencode Encode a binary file
uudecode Decode a file created by uuencode
v
v Verbosely list directory contents (`ls -l -b')
vdir Verbosely list directory contents (`ls -l -b')
vi Text Editor
vmstat Report virtual memory statistics
w
watch Execute/display a program periodically
wc Print byte, word, and line counts
whereis Report all known instances of a command
which Locate a program file in the user's path.
while Execute commands
who Print all usernames currently logged in
whoami Print the current user id and name (`id -un')
Wget Retrieve web pages or files via HTTP, HTTPS or FTP
write Send a message to another user
x
xargs Execute utility, passing constructed argument list(s)
yes Print a string until interrupted
. Run a command script in the current shell
### Comment / Remark

Source