Thursday, 28 July 2016

centOS

yum install epel-release
===============================================
yum install mod_ssl openssl
https://wiki.centos.org/HowTos/Https
https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-apache-for-centos-6
===============================================

iptables

#iptable structure is: iptables -> Tables -> Chains -> Rules.




















#http://www.thegeekstuff.com/2011/01/iptables-fundamentals
#iptables -t nat --list --> show all the available firewall rules, if you don’t specify the -t option, it will display the default filter table.
vim iptables.sh

#!/bin/bash
#enable ip forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

IPT='/sbin/iptables'

#clear iptables
#-t, --table is tables store in 
/proc/net/ip_tables_names (default is nat and filter only)
#-F, --flush is 
deleting all the rules one by one
#
-X, --delete-chain is delete the optional user-defined chain specified.
#-P, --policy is set the policy for the chain to the given chain target (eg. PREROUTING).
#nat table only got 3 predefinded chains (PREROUTING, POSTROUTING, OUTPUT)
#filter table only got 3 predefinded chains (INPUT, FORWARD, OUTPUT)
#ACCEPT – Firewall will accept the packet.
#DROP – Firewall will drop the packet.
for a in `cat /proc/net/ip_tables_names`; do
        ${IPT} -F -t $a
        ${IPT} -X -t $a

        if [ $a = nat ]; then
                ${IPT} -t nat -P PREROUTING ACCEPT
                ${IPT} -t nat -P POSTROUTING ACCEPT
                ${IPT} -t nat -P OUTPUT ACCEPT
        elif [ $a = mangle ]; then
                ${IPT} -t mangle -P PREROUTING ACCEPT
                ${IPT} -t mangle -P INPUT ACCEPT
                ${IPT} -t mangle -P FORWARD ACCEPT
                ${IPT} -t mangle -P OUTPUT ACCEPT
                ${IPT} -t mangle -P POSTROUTING ACCEPT
        elif [ $a = filter ]; then
                ${IPT} -t filter -P INPUT ACCEPT
                ${IPT} -t filter -P FORWARD ACCEPT
                ${IPT} -t filter -P OUTPUT ACCEPT
        fi
done

WAN="eth0"
LAN="eth1"
#-A, --append is append one or more rules to the end of the selected chain.
#-o, --out-interface is name of an interface via which a packet is going to be sent.
#-j, --jump is specifies the target of the rule; i.e., what to do if the packet matches it.  eg. ACCEPT, REJECT, DNAT (Destination NAT)
#MASQUERADE target is specified to mask the private IP address of a node with the external IP address of the firewall/gateway. (源地址伪装。它可以实现自动寻找到外网地址,而自动将其改为正确的外网地址。).eg. unifi router gateway, act as router or gateway. eg2. eth0 = internet and masquerade it, eth1 is 10.0.1.0 network range, without masquerading, anybody connects to the eth0 wont be able to route to the other range.

${IPT} -t nat -A POSTROUTING -o $WAN -j MASQUERADE
${IPT} -t nat -A POSTROUTING -o $LAN -j MASQUERADE

#Remote Desktop
#-i, --in-interface is name of an interface via which a packet was received.
#-d, --destination is destination specification.
#-p, --protocol is tcp, udp, icmp, icmpv6, etc.
#--dport is the destination port.
#DNAT is destination NAT.
#-m, --match is specifies  a  match  to  use.
#--state eg. 只允许状态为NEW的进来 (** 对于整个TCP协议来讲,它是一个有连接的协议,三次握手中,第一次握手,我们就叫NEW连接,而从第二次握手以后的,ack都为1,这是正常的数据传输,和tcp的第二次第三次握手,叫做已建立的连接(ESTABLISHED).

${IPT} -t nat -A PREROUTING -i $WAN -d <debian_internal_ip> -p tcp --dport 3389 -j DNAT --to <windows_internal_ip>:3389
${IPT} -A INPUT -i $WAN -d <debian_internal_ip> -p tcp --dport 3389 -j ACCEPT
${IPT} -A FORWARD -i $WAN -p tcp --dport 3389 -m state --state NEW -j ACCEPT
#Only below rules is also OK:
#iptables -t nat -A PREROUTING -p tcp --dport 3389 -j DNAT --to-destination win-box:3389
#iptables -A FORWARD -p tcp --dport 3389 -j ACCEPT




Wednesday, 27 July 2016

Debian

vim /etc/apt/sources.list
deb http://ftp.us.debian.org/debian/ jessie main
deb-src http://ftp.us.debian.org/debian/ jessie main

deb http://security.debian.org/ jessie/updates main contrib
deb-src http://security.debian.org/ jessie/updates main contrib

# jessie-updates, previously known as 'volatile'
deb http://ftp.us.debian.org/debian/ jessie-updates main contrib
deb-src http://ftp.us.debian.org/debian/ jessie-updates main contrib

====================================================================
vi
i = insert text before cursor
a= append text after cursor
o = open and put text in a new line below current line
x = delete single character under cursor
dd = delete entire current line
yy = copy the current line into the buffer
p = paste the line in the buffer into the text after the current line
====================================================================
apt-get install vim ssh htop iftop curl telnet ntp ntpdate
====================================================================
iftop -i eth0
====================================================================
ps -eaf | grep php
====================================================================
vim /etc/rc.local

ifconfig eth0:0 inet 192.168.x.x/24 up               #virtual network interface (2nd ip)
====================================================================

vim /etc/network/interfaces
source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
allow-hotplug eth0
iface eth0 inet static
        address 192.168.101.9
        netmask 255.255.254.0
        network 192.168.100.0
        broadcast 192.168.101.255
        gateway 192.168.100.1

        dns-nameservers 8.8.8.8 8.8.4.4

====================================================================
vim /root/.vimrc
set nu
syn on
set paste
set ruler
set expandtab
set tabstop=4
====================================================================
dpkg-query -f '${binary:Package}\n' -W | grep mysql
dpkg-query -f '${binary:Package}\n' -W | grep dovecot

====================================================================
apt-get install screen
screen     --> run it to enter the background screen
rsync --bwlimit=4000 -azv --progress *  root@192.168.0.62:/samba/anonymous/





Ctrl+a -> d           --> Quit from the process screen above
Ctrl+c              --> Stop the task
screen -ls             --> show detached task






screen -r                
--> Reattach a session 
ps -eaf --forest
====================================================================