Monday, October 24, 2011

āļ•ัāļ§āļ­āļĒ่āļēāļ‡āļāļēāļĢāļ—āļģ Firewall āđāļšāļš DMZ āļžāļĢ้āļ­āļĄ Transparent Proxy (DMZ āđƒāļŠ้ Private IP)

āļāļēāļĢāļˆัāļ”āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒ Firewall āđāļšāļš DMZ (Demilitarized Zone) āđ€āļ›็āļ™āļĢูāļ›āđāļšāļšāļŦāļ™ึ่āļ‡āļ—ี่āļ™ิāļĒāļĄāđƒāļŠ้āļัāļ™  āļ‹ึ่āļ‡āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļˆāļ°āļ›āļĢāļ°āļāļ­āļšāđ„āļ›āļ”้āļ§āļĒāđ€āļ„āļĢืāļ­āļ‚่āļēāļĒ 3 āļŠ่āļ§āļ™āļ”้āļ§āļĒāļัāļ™ āļ„ืāļ­
1 .āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļ āļēāļĒāđƒāļ™ 
(trusted internal network) āļˆāļ°āđ€āļ›็āļ™āļŠ่āļ§āļ™āļ—ี่āđ„āļĄ่āļ­āļ™ุāļāļēāļ•āđƒāļŦ้āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļ āļēāļĒāļ™āļ­āļāđ€āļ‚้āļēāļĄāļēāđ„āļ”้ āļ‹ึ่āļ‡āļŠ่āļ§āļ™āđƒāļŦāļ่āļˆāļ°āđ€āļ›็āļ™āļŠ่āļ§āļ™āļ‚āļ­āļ‡ Client
2. āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒ
DMZ āđ€āļ›็āļ™āļŠ่āļ§āļ™āļ—ี่āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļ āļēāļĒāļ™āļ­āļāđāļĨāļ°āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļ āļēāļĒāđƒāļ™āđ€āļ‚้āļēāļĄāļēāđƒāļŠ้āļ‡āļēāļ™āđ„āļ”้āļ•āļēāļĄāļāļŽāļ—ี่ Firewall āđ„āļ”้āļ•ั้āļ‡āđ„āļ§้
3.āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļ āļēāļĒāļ™āļ­āļ (Internet)

āđ‚āļ”āļĒāļāļēāļĢāđ€āļŠื่āļ­āļĄāļ•่āļ­āđƒāļŠ้āļ‡āļēāļ™āļˆāļ°āļ•้āļ­āļ‡āļĄี
Linux Server āļ•ัāļ§āļŦāļ™ี่āļ‡āļ—āļģāļŦāļ™้āļēāļ—ี่āđ€āļ›็āļ™ Firewall āļ‹ึ่āļ‡āļˆāļ°āļ•้āļ­āļ‡āļ›āļĢāļ°āļāļ­āļšāļ”้āļ§āļĒāļāļēāļĢ์āļ”āđāļĨāļ™ 3 āļāļēāļĢ์āļ” āļ”ัāļ‡āļĢูāļ›āļ—ี่ 1



āļĢูāļ›āļ—ี่ 1
āđ€āļžื่āļ­āđƒāļŦ้āđ€āļ‚้āļēāđƒāļˆāđ„āļ”้āļ‡่āļēāļĒāļ‚ึ้āļ™āļˆึāļ‡āļ‚āļ­āđƒāļŠ้āļĢูāļ›āļ•ัāļ§āļ­āļĒ่āļēāļ‡āļāļēāļĢāđ€āļŠื่āļ­āļĄāļ•่āļ­āļˆāļĢิāļ‡ āđ† āļ”ัāļ‡āļĢูāļ›āļ—ี่ 2  āļ‹ึ่āļ‡āļ—ี่ Linux Firewall āļˆāļ°āļĄี Ethernet Card 3 āļāļēāļĢ์āļ”āļ„ืāļ­ eth0 āđƒāļŠ้āđ€āļŠื่āļ­āļĄāļ•่āļ­āļัāļšāđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļ āļēāļĒāļ™āļ­āļ, eth1 āđƒāļŠ้āđ€āļŠื่āļ­āļĄāļ•่āļ­āļัāļšāđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļ āļēāļĒāđƒāļ™  āđāļĨāļ° eth2 āđƒāļŠ้āđ€āļŠื่āļ­āļĄāļ•่āļ­āļัāļšāđ€āļ„āļĢืāļ­āļ‚่āļēāļĒ DMZ  āđƒāļ™āļŠ่āļ§āļ™āļ‚āļ­āļ‡ eth0 āļ™ั้āļ™āļĄี IP Address āđ€āļ›็āļ™ 3 āļ„่āļēāļ„ืāļ­
1. 202.129.49.194
āđāļ—āļ™āļ•ัāļ§āđ€āļ­āļ‡āļ‹ึ่āļ‡āđ€āļ›็āļ™ Firewall
2. 202.129.49.195 āđƒāļŠ้āđāļ—āļ™
HTTP
3. 202.129.49.196
āđƒāļŠ้āđāļ—āļ™ DNS

āļŦāļĄāļēāļĒāđ€āļŦāļ•ุ Proxy āđ„āļĄ่āļˆāļģāđ€āļ›็āļ™āļ•้āļ­āļ‡āđƒāļŦ้āļšāļĢิāļāļēāļĢāļัāļšāļšุāļ„āļ„āļĨāļ āļēāļĒāļ™āļ­āļ āļˆึāļ‡āđ„āļĄ่āļˆāļģāđ€āļ›็āļ™āļ•้āļ­āļ‡āđƒāļŠ้ IP āļˆāļĢิāļ‡



āļĢูāļ›āļ—ี่ 2
āļŦāļ™้āļēāļ—ี่āļ‚āļ­āļ‡ Linux Firewall
1.āļ—āļģ NAT (Outbound) āđƒāļŦ้āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļ āļēāļĒāđƒāļ™ (trusted internal network) āļŠāļēāļĄāļēāļĢāļ–āđ€āļŠื่āļ­āļĄāļ•่āļ­āđ„āļ›āļĒัāļ‡āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļ āļēāļĒāļ™āļ­āļāđ„āļ”้
2.āđƒāļ™āļāļĢāļ“ีāļ—ี่āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļ āļēāļĒāđƒāļ™āļ­āļ­āļāđ„āļ›āđƒāļŠ้āļ‡āļēāļ™āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļ āļēāļĒāļ™āļ­āļāđ€āļ›็āļ™āļāļēāļĢāđ€āļĢีāļĒāļāđƒāļŠ้ http āđƒāļŦ้ redirect āđ„āļ›āļĒัāļ‡ Proxy āļ‚āļ­āļ‡ DMZ (Transparent Proxy)
3.
Linux Server āļ•้āļ­āļ‡āļ­āļ™ุāļāļēāļ•āđƒāļŦ้āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļ āļēāļĒāđƒāļ™āļŠāļēāļĄāļēāļĢāļ–āđƒāļŠ้āļ‡āļēāļ™ DNS Server āđƒāļ™āļ§āļ‡ DMZ āļ—ั้āļ‡āļāļēāļĢāđ€āļĢีāļĒāļāđ‚āļ”āļĒāđƒāļŠ้ IP āļˆāļĢิāļ‡āđāļĨāļ° IP āļ›āļĨāļ­āļĄāđ„āļ”้ (āļ—ั้āļ‡ 202.129.49.196 āđāļĨāļ° 192.168.2.3)
4.
Linux Server āļ•้āļ­āļ‡āļ­āļ™ุāļāļēāļ•āđƒāļŦ้āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļ āļēāļĒāđƒāļ™āļŠāļēāļĄāļēāļĢāļ–āđƒāļŠ้āļ‡āļēāļ™ Web Server āđƒāļ™āļ§āļ‡ DMZ āļ—ั้āļ‡āļāļēāļĢāđ€āļĢีāļĒāļāđ‚āļ”āļĒāđƒāļŠ้ IP āļˆāļĢิāļ‡āđāļĨāļ° IP āļ›āļĨāļ­āļĄ (āļ—ั้āļ‡ 202.129.49.195 āđāļĨāļ° 192.168.2.2)
5
.āļ—āļģ NAT (Inbound) āđƒāļŦ้āđ€āļ„āļĢืāļ­āļ‚่āļēāļĒāļ āļēāļĒāļ™āļ­āļāđ€āļ‚้āļēāļĄāļēāđƒāļŠ้ Web Server āđāļĨāļ° DNS Server āđƒāļ™āļ§āļ‡  DMZ āđ„āļ”้
6.āļ—āļģāļŦāļ™้āļēāļ—ี่āđ€āļ›็āļ™
Firewall

āļ„āļģāļŠั่āļ‡
iptables āļ—ี่āđƒāļŠ้
āļ„āļģāļŠั่āļ‡āļ—ี่āđƒāļŠ้āļ—ั้āļ‡āļŦāļĄāļ”āđ€āļ›็āļ™āļ”ัāļ‡āļ™ี้
:

#-----Start script------#

#Define variables
LAN_IP="192.168.1.1"
LAN_BCAST_ADRESS="192.168.1.255"
LAN_IFACE="eth1"

INET_IP="202.129.49.194"
INET_IFACE="eth0"

HTTP_IP="202.129.49.195"
DNS_IP="202.129.49.196"

DMZ_IP="192.168.2.1"
DMZ_IFACE="eth2"

DMZ_HTTP_IP="192.168.2.2"
DMZ_DNS_IP="192.168.2.3"
DMZ_PROXY_IP="192.168.2.4"

LO_IP="127.0.0.1"
LO_IFACE="lo"
#CRITICAL: Enable IP forwarding since it is disabled by default.
echo "1" > /proc/sys/net/ipv4/ip_forward
#Clear all chains of rule
iptables -F
iptables -X allowed
iptables -X icmp_packets
iptables -t nat -F

# Chain Policies gets set up before any bad packets gets through
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP

# the allowed chain for TCP connections, utilized in the FORWARD chain
iptables -N allowed
iptables -A allowed -p TCP --syn -j ACCEPT
iptables -A allowed -p TCP -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A allowed -p TCP -j DROP

# ICMP rules, utilized in the FORWARD chain
iptables -N icmp_packets
iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 0 -j ACCEPT
iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 3 -j ACCEPT
iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 5 -j ACCEPT
iptables -A icmp_packets -p ICMP -s 0/0 --icmp-type 11 -j ACCEPT

# POSTROUTING chain in the nat table : Enable IP SNAT for all internal networks trying to get out on the Internet
iptables -t nat -A POSTROUTING -o $INET_IFACE -j SNAT --to-source $INET_IP

# PREROUTING chain in the nat table

         
# Do some checks for obviously spoofed IP's
iptables -t nat -A PREROUTING -i $INET_IFACE -s 192.168.0.0/16 -j DROP
iptables -t nat -A PREROUTING -i $INET_IFACE -s 10.0.0.0/8 -j DROP
iptables -t nat -A PREROUTING -i $INET_IFACE -s 172.16.0.0/12 -j DROP
iptables -t nat -A PREROUTING -i $INET_IFACE -s $INET_IP -j DROP

          # Enable IP Destination NAT for DMZ zone (Inbound NAT)
iptables -t nat -A PREROUTING -p TCP -i $INET_IFACE -d $HTTP_IP --dport 80 -j DNAT --to-destination $DMZ_HTTP_IP
iptables -t nat -A PREROUTING -p TCP -i $INET_IFACE -d $DNS_IP --dport 53 -j DNAT --to-destination $DMZ_DNS_IP
iptables -t nat -A PREROUTING -p UDP -i $INET_IFACE -d $DNS_IP --dport 53 -j DNAT --to-destination $DMZ_DNS_IP
          # Enable Internal network connect to DMZ HTTP and DMZ DNS by public IP (update by Adisorn)
iptables -t nat -A PREROUTING -p TCP -i $LAN_IFACE -d $HTTP_IP --dport 80 -j DNAT --to-destination $DMZ_HTTP_IP
iptables -t nat -A PREROUTING -p TCP -i $LAN_IFACE -d $DNS_IP --dport 53 -j DNAT --to-destination $DMZ_DNS_IP
iptables -t nat -A PREROUTING -p UDP -i $LAN_IFACE -d $DNS_IP --dport 53 -j DNAT --to-destination $DMZ_DNS_IP

          #Redirect all http from internal network (not DMZ http destination) to Proxy Server (Transparent Proxy) (update by sorn)
iptables -t nat -A PREROUTING -p TCP -i $LAN_IFACE -s 192.168.1.0/24 -d ! $DMZ_HTTP_IP --dport 80 -j DNAT --to-dest 192.168.2.4:3128
# FORWARD chain

         
# Get rid of bad TCP packets
iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j LOG --log-prefix "New not syn:"
iptables -A FORWARD -p tcp ! --syn -m state --state NEW -j DROP

          # DMZ section : General rules
iptables -A FORWARD -i $DMZ_IFACE -o $INET_IFACE -j ACCEPT
iptables -A FORWARD -i $INET_IFACE -o $DMZ_IFACE -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -i $LAN_IFACE -o $DMZ_IFACE -j ACCEPT
iptables -A FORWARD -i $DMZ_IFACE -o $LAN_IFACE -j ACCEPT

          # DMZ section : HTTP server
iptables -A FORWARD -p TCP -i $INET_IFACE -o $DMZ_IFACE -d $DMZ_HTTP_IP --dport 80 -j allowed
iptables -A FORWARD -p ICMP -i $INET_IFACE -o $DMZ_IFACE -d $DMZ_HTTP_IP -j icmp_packets         

          #DMZ section : DNS server
iptables -A FORWARD -p TCP -i $INET_IFACE -o $DMZ_IFACE -d $DMZ_DNS_IP --dport 53 -j allowed
iptables -A FORWARD -p UDP -i $INET_IFACE -o $DMZ_IFACE -d $DMZ_DNS_IP --dport 53 -j ACCEPT
iptables -A FORWARD -p ICMP -i $INET_IFACE -o $DMZ_IFACE -d $DMZ_DNS_IP -j icmp_packets                   
          # LAN section
iptables -A FORWARD -i $LAN_IFACE -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

          # LOG all packets reaching here
iptables -A FORWARD -m limit --limit 3/minute --limit-burst 3 -j LOG --log-level DEBUG --log-prefix "IPT FORWARD packet died: "

# Firewall rules

         
# INPUT chain

                    #Get rid of bad packets
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j LOG --log-prefix "New not syn:"
iptables -A INPUT -p tcp ! --syn -m state --state NEW -j DROP
                    # Packets from the Internet to this box
iptables -A INPUT -p ICMP -i $INET_IFACE -j icmp_packets

                    # Packets from LAN, DMZ or LOCALHOST

                              # From DMZ Interface to DMZ firewall IP
iptables -A INPUT -p ALL -i $DMZ_IFACE -d $DMZ_IP -j ACCEPT

                              # From LAN Interface to LAN firewall IP
iptables -A INPUT -p ALL -i $LAN_IFACE -d $LAN_IP -j ACCEPT
iptables -A INPUT -p ALL -i $LAN_IFACE -d $LAN_BCAST_ADRESS -j ACCEPT
                              # From Localhost interface to Localhost IP
iptables -A INPUT -p ALL -i $LO_IFACE -d $LO_IP -j ACCEPT
                    # All established and related packets incoming from the internet to the firewall
iptables -A INPUT -p ALL -d $INET_IP -m state --state ESTABLISHED,RELATED -j ACCEPT
                    # Logging rule
iptables -A INPUT -m limit --limit 3/minute --limit-burst 3 -j LOG --log-level DEBUG --log-prefix "IPT INPUT packet died: "
          # OUTPUT chain

                    # Get rid of bad TCP packets
iptables -A OUTPUT -p tcp ! --syn -m state --state NEW -j LOG --log-prefix "New not syn:"
iptables -A OUTPUT -p tcp ! --syn -m state --state NEW -j DROP
                    # Allow ourself to send packets not spoofed everywhere
iptables -A OUTPUT -p ALL -o $LO_IFACE -s $LO_IP -j ACCEPT
iptables -A OUTPUT -p ALL -o $LAN_IFACE -s $LAN_IP -j ACCEPT
iptables -A OUTPUT -p ALL -o $INET_IFACE -s $INET_IP -j ACCEPT
                    # Logging rule
iptables -A OUTPUT -m limit --limit 3/minute --limit-burst 3 -j LOG --log-level DEBUG --log-prefix "IPT OUTPUT packet died: "

#-----End script------#

āļāļēāļĢāļ—āļģ DMZ

āđ€āļŠ่āļ™ 202.29.30.49 map 192.168.2.19 āļŠāļēāļĄāļēāļĢāļ–āđ€āļĢีāļĒāļāļ”ูāđ„āļ”้ āļ—ี่
202.29.30.49 āļ„āļĢัāļš


āđ€āļ‚āļēāđ€āļĢีāļĒāļāļ§่āļēāļāļēāļĢāļ—āļģ DMZ āļ„āļĢัāļš āļ„ืāļ­āļ•้āļ­āļ‡āļĄีāļāļēāļĢ์āļ”āđāļĨāļ™āđ€āļžิ่āļĄāļĄāļēāļ­ีāļāđƒāļšāļ™ึāļ‡āļ„ัāļš āđ€āļ—่āļēāļ—ี่āļ—āļĢāļēāļš āđāļ•่āļ§่āļēāļœāļĄāļ็āļĒัāļ‡āđ„āļĄ่āđ€āļ„āļĒāļ—āļģ

āļ›āļĨ. āđ„āļĄ่āļĢู้āļœāļĄāđ€āļ‚้āļēāđƒāļˆāļ–ูāļāļŦāļĢืāļ­āđ€āļ›āļĨ่āļēāļ™āļ°āļ„āļĢัāļš āļ—ี่āļœāļĄāđ€āļ‚้āļēāđƒāļˆāļ็āļ„ืāļ­ āļ­āļĒ่āļēāļ‡āđ€āļŠ่āļ™āđ€āļĢāļēāđ€āļ‚้āļē 202.29.30.49:80 āļ็āđƒāļŦ้āļ§ิ่āļ‡āđ„āļ›āđ€āļ›ิāļ”āđ€āļ„āļĢื่āļ­āļ‡ 192.168.2.19:80 āđƒāļŠāļ›่āļ°āļ„ัāļš āļ–้āļēāđƒāļŠ่āđ€āļ‚āļēāđ€āļĢีāļĒāļāļ—āļģ DMZ āļ„āļĢัāļš
āđƒāļŠ้ ipnat āļ„āļĢัāļš
āđ€āļ›ิāļ” ipnat āđƒāļŦ้āļ—āļģāļ‡āļēāļ™āđ‚āļ”āļĒāđ€āļžิ่āļĄāđƒāļ™āđ„āļŸāļĨ์ /etc/rc.conf āļ”ัāļ‡āļ™ี้
ipnat_enable="YES"
ipnat_rules="/etc/ipnat.rules"

āđāļĨ้āļ§āđ€āļžิ่āļĄāļāļŽāļ™ี้āđ€āļ‚้āļēāđ„āļ›āđƒāļ™ /etc/ipnat.rules
rdr rl1 0.0.0.0/0 port 8081 -> 192.168.0.252 port 80 tcp

āđ‚āļ”āļĒ rl1 āļ„ืāļ­āļāļēāļĢ์āļ”āđāļĨāļ™āđƒāļšāļ—ี่āļ•้āļ­āļ‡āļāļēāļĢāđƒāļŦ้ forward āļĄāļē āļ­āļēāļˆāļˆāļ°āđ€āļ›็āļ™ ip āļˆāļĢิāļ‡āļั่āļ‡āļ—ี่āļ•่āļ­āļัāļšāļ­ิāļ™āđ€āļ•āļ­āļĢ์āđ€āļ™็āļ• āđ‚āļ”āļĒāļžāļ­āļĢ์āļ• 8081 āļ„ืāļ­āļŦāļĄāļēāļĒāđ€āļĨāļ‚āļžāļ­āļĢ์āļ•āļ—ี่āđ€āļĢีāļĒāļāđ€āļ‚้āļēāļĄāļē
āđ€āļŠ่āļ™ āļāļēāļĢ์āļ”āđāļĨāļ™āđƒāļšāļ™ี้(rl1)āļĄี ip 202.222.123.5 āļ–้āļēāđ€āļĢีāļĒāļāļœ่āļēāļ™ potocol http āļ็āđ€āļĢีāļĒāļāđ‚āļ”āļĒhttp://202.222.123.5:8081āļĄัāļ™āļ็āļˆāļ° forward āđ„āļ›āļ—ี่ 192.168.0.252 āļžāļ­āļĢ์āļ• 80

āļ•ัāļ§āļ­āļĒ่āļēāļ‡
rdr rl1 0.0.0.0/0 port 8081 -> 192.168.0.252 port 80 tcp
rdr rl1 0.0.0.0/0 port 22 -> 192.168.0.3 port 22 tcp
rdr rl1 0.0.0.0/0 port 80 -> 192.168.0.4 port 80 tcp
rdr rl1 0.0.0.0/0 port 25 -> 192.168.0.4 port 25 tcp

   
āđ€āļžิ่āļĄāđ€āļ•ิāļĄāļ„āļĢัāļš
āđ€āļ„āļĢื่āļ­āļ‡āļ—ี่āļ—āļģ port forwarding āļ•้āļ­āļ‡āļĄีāđāļĨāļ™āļāļēāļĢ์āļ”āļ­āļĒ่āļēāļ‡āļ™้āļ­āļĒāļŠāļ­āļ‡āđƒāļš āļ„ืāļ­ ip āļˆāļĢิāļ‡ āļัāļš ip āļ›āļĨāļ­āļĄ

āļ–้āļēāļ—āļģ port forwarding āļˆāļēāļ router āđƒāļŠ้āļ„āļģāļŠั่āļ‡āļ”ัāļ‡āļ™ี้āļ„āļĢัāļš
ip nat inside source static tcp 192.168.0.50 80 interface serial0 80

āđ‚āļ”āļĒ 192.168.0.50 80 āļ„ืāļ­ ip āļ›āļĨāļ­āļĄ āļัāļš āļžāļ­āļĢ์āļ• āļ—ี่āļ•้āļ­āļ‡āļāļēāļĢāđƒāļŦ้ forward āļĄāļē

serial0 80 āļ„ืāļ­ interface āļั่āļ‡ WAN āļ—ี่āļ­āļ­āļāđ€āļ™็āļ•

/sbin/iptab/sbin/iptables -t nat -A PREROUTING -p tcp -s x/x -d [ip.address āļั่āļ‡ wan āļ‚āļ­āļ‡āļ„ุāļ“] -i [wan-interface-name] --dport 80 -j DNAT --to-destination 192.168.1.100:80


āļāļĢāļ“ีāļ—ี่āđ€āļĢāļēāļĄี web1, web2 āļ–้āļēāļāļģāļŦāļ™āļ” rules āđāļšāļšāļ™ี้āļĄัāļ™āļˆāļ°āļ‡āļ‡āļĄั๊āļĒāļ„āļĢัāļš

rdr rl1 0.0.0.0/0 port 80 -> 192.168.0.4 port 80 tcp
rdr rl1 0.0.0.0/0 port 80 -> 192.168.0.5 port 80 tcp

āļāļģāļŦāļ™āļ”āļ‹้āļ­āļ™āļัāļ™āđ„āļĄ่āđ„āļ”้āļ„āļĢัāļš āļ–้āļē 2 āđ€āļ§็āļšāļ็āļ•้āļ­āļ‡āļĢัāļ™āļัāļ™āļ„āļ™āļĨāļ° port āļ„āļĢัāļš

āļ‡ั้āļ™āļ•้āļ­āļ‡āđ€āļ›็āļ™āđāļšāļšāļ™ี้āļĢึāđ€āļ›āļĨ่āļēāļ„āļĢัāļš

rdr rl1 0.0.0.0/0 port 80 -> 192.168.0.4 port 80 tcp (web1)
rdr rl1 0.0.0.0/0 port 81 -> 192.168.0.5 port 80 tcp (web2)

āđāļĨ้āļ§āđ€āļ§āļĨāļēāđ€āļ‚้āļēāđ€āļ§āļ›āļĨ่āļ°āļ„āļĢัāļš āļāļĢāļ“ีāļ—ี่āđ€āļ›็āļ™ web2 āļ•้āļ­āļ‡āđ€āļ›็āļ™ www.web2.com:81 āļĢึāđ€āļ›āļĨ่āļēāļ„āļĢัāļš āļ–้āļēāđ€āļ›็āļ™āļ­āļĒ่āļēāļ‡āļ™ี้āđ€āļĢāļēāļˆāļ°āļĄีāļ§ิāļ˜ีāđāļ้āļĒัāļ‡āļ‡ัāļĒāļ„āļĢัāļšāđƒāļŦ้ user āđ€āļ„้āļēāđ€āļ‚้āļēāđ„āļ”้āđāļšāļšāļ›āļāļ•ิāļ™่āļ°āļ„āļĢัāļšāļ„ืāļ­

www.web2.com āļ­āļĒ่āļēāļ‡āļ™ี้āđ€āļĨāļĒ...āļĢāļšāļāļ§āļ™āļ”้āļ§āļĒāļ™āļ°āļ„āļĢัāļš āļœāļĄāļŠāļ‡āļŠัāļĒāļˆāļĢิāļ‡āđ† āļ‚āļ­āļšāļ„ุāļ“āļ„āļĢัāļš

Sunday, October 23, 2011

Domain forwarding in Apache

Domain forwarding in Apache

Here's a short tutorial on one way to forward one domain to another in Apache, keeping Google happy as we go along.

The disclaimer bit

First of all this tutorial is based on Apache 2.2 on Centos 5. No responsibility will be taken for things going wrong so use at your own risk!

What we want to achieve

Let's say we have a client who wants to forward three domains to one. For this example let's use:
  • www.ilovemymonkeys.com
  • www.monkeysarecool.com
  • www.monkeysrockmyworld.com
The domain the client wants all of these forwarded to is
  • www.monkeyworld.com

Is it really worth it?

Well not really no. If you can pursuade the client it is probably best to park these additional domains that have been registered. There is not going to be a great deal of benefit, if any, for SEO. But if you really need to do it here's how.

What you'll need

This article assumes you have command line access to your box. If you don't then you'll need to contact your hosting company and explain your requirements

Virtual hosts

It is likely you'll be using Name Based Virtual Hosts in Apache. If you haven't set up Virtual Hosts it is a great way to manage sites so be sure to read up on it. Presuming you have an entry for monkeyworld.com we need to edit/create it in our virtual hosts file. The location of where you should place this varies depending on what flavour of Linux you are running. On Centos 5 you can create a file in /etc/httpd/conf.d with the appenedix .conf and it will be picked up when Apache is started.
vi /etc/httpd/conf.d/httpd-vhosts.conf 
NameVirtualHost *:80 
# Monkey World 
<VirtualHost *:80> 
  <Directory /var/www/vhosts/monkeysarecool.com/httpdocs> 
    AllowOverride All 
  </Directory> 
    DocumentRoot /var/www/vhosts/monkeysarecool.com/httpdocs 
    ServerName www.monkeysarecool.com 
    ServerAlias ilovemonkeys.com monkeysarecool.co.uk monkeysrockmyworld.co.uk 
    ServerAlias www.ilovemonkeys.com www.monkeysarecool.co.uk www.monkeysrockmyworld.co.uk Include /var/www/vhosts/monkeysarecool.com/conf/vhost.conf 
</VirtualHost> 
You'll see the lines Server Alias have listings for the domains both with www and without. This ensures you can receive requests with and without www. I like to put them on separate lines so I can see I have what's happening.
Finally there is an Include line. This points to an additional configuration file for the domain. You could use an .htaccess file here but if you have root access to the box it is much more efficient performance wise to put it in an additional configuration file.

Forwarding the domain

So far we've set up requests for Apache to serve up monkeyworld.com for our additional domains. You could leave it like this and restart Apache to have the same content served up on these domains. This is a bad thing for Google though and it is likely your rankings will slip down with duplicate content on multiple domains.
So we want to forward the domain. To do that lets open our additional configuration file:
vi /var/www/vhosts/monkeysarecool.com/conf/vhost.conf
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(monkeyworld.com|ilovemonkeys.com|monkeysarecool.co.uk|monkeysrockmyworld.co.uk) [NC] 
RewriteRule ^(.*)$ http://www.monkeyworld.com$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^(www.ilovemonkeys.com|www.monkeysarecool.co.uk|www.monkeysrockmyworld.co.uk) [NC] 
RewriteRule ^(.*)$ http://www.circalibrary.com$1 [R=301,L]
We're using Apache's mod_rewrite to send redirect requests and return a 301 Moved Permanently Header. This should help Google and any other bots to understand what we're doing. Again I like separate entries for with and without www but that's personal preference.
Save this file. We should be done but before restarting Apache let's test that we haven't made any syntax errors that will stop the server from starting up.
/etc/init.d/httpd configtest
If you get "Syntax OK" you are good to restart the server:
/etc/init.d/httpd restart
All done! So now when you hit www.ilovemonkeys.com, monkeysarecool.co.uk or monkeysrockmyworld.co.uk you will be forwarded monkeyworld.com, with the address being changed as well.

Saturday, October 22, 2011

āļāļēāļĢ āļ•ั้āļ‡āđ€āļ§āļĨāļē reboot āļ”้āļ§āļĒ crontab āļšāļ™ CentOS

āļāļēāļĢ āļ•ั้āļ‡āđ€āļ§āļĨāļē reboot āļ”้āļ§āļĒ crontab āļšāļ™ CentOS

āļ§ิāļ˜ีāļāļēāļĢāļ—āļģāļ™ั้āļ™āļ‡āļēāļĒāļĄāļēāļāļ„āļĢัāļšāđƒāļŠ้āļ§ิāļ˜ีāļāļēāļĢāđ€āļ‚้āļēāđ„āļ›āđ€āļžิ่āļĄāļāļēāļĢāļ—āļģāļ‡āļēāļ™ crontab āļ”้āļ§āļĒāļ„āļģāļŠั่āļ‡

# crontab -e
āļˆāļēāļāļ™ั้āļ™āđ€āļžิ่āļĄāļŠ่āļ§āļ‡āđ€āļ§āļĨāļēāđ€āļžื่āļ­ reboot āļ„āļĢัāļšāļ•ัāļ§āļ­āļĒ่āļēāļ‡āļœāļĄāļ­āļĒāļēāļāđƒāļŦ้āđ€āļ„āļĢื่āļ­āļ‡ reboot āļ—ุāļāļ§ัāļ™āđƒāļ™āđ€āļ§āļĨāļē 2.00 āļ”้āļ§āļĒāļ„āļģāļŠั่āļ‡
# 0 2 * * * /sbin/shutdown -r now
āļˆāļēāļāļ™ั้āļ™āļ็ :wr āđ€āļžื่āļ­ save āļ„āļĢัāļš āđāļĨāļ°āđ€āļĢิ่āļĄāļāļēāļĢāļ—āļģāļ‡āļēāļ™āļ‚āļ­āļ‡ crontab āđƒāļŦāļĄ่āđ‚āļ”āļĒāđƒāļŠ้āļ„āļģāļŠั่āļ‡
# service crond restart

āļ„āļģāļŠั่āļ‡ crontab

āļ„āļģāļŠั่āļ‡ crontab āđ€āļ›็āļ™āļ„āļģāļŠั่āļ‡āđƒāļ™ āļāļēāļĢāļ—āļģ schedule āđƒāļ™āļāļēāļĢāļŠั่āļ‡āđ‚āļ›āļĢāđāļāļĢāļĄ āļŦāļĢืāļ­ script āļ•่āļēāļ‡āđ† āļ—āļģāļ‡āļēāļ™āļ•āļēāļĄāđ€āļ§āļĨāļēāļ—ี่āļāļģāļŦāļ™āļ” āļšāļ™āļĢāļ°āļšāļš UNIX/LINUX
āļ‹ึ่āļ‡āļ­āļģāļ™āļ§āļĒāļ„āļ§āļēāļĄāļŠāļ°āļ”āļ§āļ āđ„āļ”้āļĄāļēāļāđ€āļĨāļĒāļ—ี่āđ€āļ”ีāļĒāļ§ āļ‡āļēāļ™āļšāļēāļ‡āļ­āļĒ่āļēāļ‡āļ—ี่āļˆāļģāđ€āļ›็āļ™āļ•้āļ­āļ‡āļ—āļģāļ‹้āļģāđ†āđƒāļ™āđ€āļ§āļĨāļēāđ€āļ”ีāļĒāļ§āļัāļ™ āđ„āļĄ่āļ§่āļēāļˆāļ°āļ—ุāļāļ§ัāļ™ āļ—ุāļāļŠัāļ›āļ”āļēāļŦ์ āļŦāļĢืāļ­ āļ—ุāļāđ€āļ”ืāļ­āļ™
āļāļēāļĢāđƒāļŠ้ āļ‡āļēāļ™ crontab
------------------------
āļ„āļģāļŠั่āļ‡ āđāļĨāļ° option āļ‚āļ­āļ‡ crontab āļĄี āļ”ัāļ‡āļ™ี้
Code:
crontab filename āļāļēāļĢāļ™āļģāđ€āļ­āļēāļ„āļģāļŠั่āļ‡ crontab āđ€āļ‚้āļēāļĄāļēāļˆāļēāļ āđ„āļŸāļĨ์āļ­ื่āļ™
crontab -e āđāļ้āđ„āļ‚ crontab āļ›ัāļˆāļˆุāļšัāļ™
crontab -l āļ”ูāļ„āļģāļŠั่āļ‡ crontab āļ—ั้āļ‡āļŦāļĄāļ”āļ—ี่āļĄีāļ­āļĒู่
crontab -r āļĨāļšāļ„āļģ āļŠั่āļ‡ crontab āļ—ี่āļĄีāļ—ั้āļ‡āļŦāļĄāļ”
crontab -u user āđ€āļ›็āļ™āļ„āļģāļŠั่āļ‡āļ‚āļ­āļ‡āļœู้āļ”ูāđāļĨāļĢāļ°āļšāļšāđ€āļ—่āļēāļ™ั้āļ™(administrators) āđ€āļžื่āļ­āđƒāļŠ้āļ”ู āđāļ้āđ„āļ‚ āļĨāļš crontab āļ‚āļ­āļ‡ user āđāļ•่ āļĨ่āļ°āļ„āļ™
āđ€āļĄื่āļ­āđ€āļĢีāļĒāļāļ„āļģāļŠั่āļ‡āļ•āļēāļĄāļ‚้āļēāļ‡āļšāļ™āđāļĨ้āļ§ crontab āļˆāļ° āđ€āļ‚้āļēāļŠู่āļĢāļ°āļšāļšāļāļēāļĢ āļāļģāļŦāļ™āļ” āļŦāļĢืāļ­ āđāļ้āđ„āļ‚ āļ‹ึ่āļ‡āļāļēāļĢ āļāļģāļŦāļ™āļ” āļŦāļĢืāļ­āđāļ้āđ„āļ‚āļ™ี้ āļˆāļ°āđ€āļŦāļĄืāļ­āļ™āļัāļšāļāļēāļĢāđƒāļŠ้āļ‡āļēāļ™ vi āļ„āļĢัāļš
āļāļēāļĢāļāļģāļŦāļ™āļ”āđƒāļŦ้ crontab āļ—āļģāļ‡āļēāļ™
-------------------------------------
format āļ‚āļ­āļ‡āļ„āļģāļŠั่āļ‡ crontab āļĄีāļ—ั้āļ‡āļŦāļĄāļ” 6 fields āđ€āļ›็āļ™āļ”ัāļ‡āļšāļĢāļĢāļ—ัāļ”āļ‚้āļēāļ‡āļĨ่āļēāļ‡
Code:
minute(s) hour(s) day(s) month(s) weekday(s) command(s)
fields 1-5 āđ€āļ›็āļ™āļāļēāļĢāļāļģāļŦāļ™āļ”āđ€āļ§āļĨāļē āđāļĨāļ° field āļ—ี่ 6 āđ€āļ›็āļ™āļāļēāļĢāļāļģāļŦāļ™āļ”āļ„āļģāļŠั่āļ‡ āļ”ัāļ‡āļ„āļ§āļēāļĄāļŦāļĄāļēāļĒāļ‚āļ­āļ‡āđāļ•่āļĨāļ° fields āļ”ัāļ‡āļ•่āļ­āđ„āļ›āļ™ี้
Code:
........................................................................................................................................
Field āļĄีāļ„่āļē āļĢāļēāļĒāļĨāļ°āđ€āļ­ีāļĒāļ”
........................................................................................................................................
minute 0-59 āđ€āļ§āļĨāļē āđ€āļ›็āļ™āļ™āļēāļ—ี āļˆāļ°āļŠั่āļ‡āđƒāļŦ้āļ„āļģāļŠั่āļ‡āļ—ี่āļāļģāļŦāļ™āļ”āļ—āļģāļ‡āļēāļ™āļ—ัāļ™āļ—ีāđ€āļĄื่āļ­āļ–ึāļ‡
hour 0-23 āđ€āļ§āļĨāļē āđ€āļ›็āļ™āļŠั่āļ§āđ‚āļĄāļ‡ āļˆāļ°āļŠั่āļ‡āđƒāļŦ้āļ„āļģāļŠั่āļ‡āļ—ี่āļāļģāļŦāļ™āļ”āļ—āļģāļ‡āļēāļ™āļ—ัāļ™āļ—ีāđ€āļĄื่āļ­āļ–ึāļ‡
day 1-31 āđ€āļ§āļĨāļēāđ€āļ›็āļ™āļ§ัāļ™ āļˆāļ°āļŠั่āļ‡āđƒāļŦ้āļ„āļģāļŠั่āļ‡āļ—ี่āļāļģāļŦāļ™āļ”āļ—āļģāļ‡āļēāļ™āļ—ัāļ™āļ—ีāđ€āļĄื่āļ­āļ–ึāļ‡
month 1-12 āđ€āļ§āļĨāļē āđ€āļ›็āļ™āđ€āļ”ืāļ­āļ™ āļˆāļ°āļŠั่āļ‡āđƒāļŦ้āļ„āļģāļŠั่āļ‡āļ—ี่āļāļģāļŦāļ™āļ”āļ—āļģāļ‡āļēāļ™āļ—ัāļ™āļ—ีāđ€āļĄื่āļ­āļ–ึāļ‡
weekday 0-6 āļ§ัāļ™ āļ‚āļ­āļ‡āđāļ•่āļĨāļ°āļŠัāļ›āļ”āļēāļŦ์ āļĄีāļ„่āļēāļ”ัāļ‡āļ™ี้ (āļ­āļēāļ—ิāļ•āļĒ์ = 0, āļˆัāļ™āļ—āļĢ์ = 1, āļ­ัāļ‡āļ„āļēāļĢ = 2, āļžุāļ˜ = 3, āļžāļĪāļŦัāļŠ = 4, āļĻุāļāļĢ์ = 5 āđāļĨāļ° āđ€āļŠāļēāļĢ์ = 6)
command āļ„āļģāļŠั่āļ‡ āđ€āļĢāļēāļŠāļēāļĄāļēāļĢāļ–āļāļģāļŦāļ™āļ”āļ„āļģāļŠั่āļ‡āđ„āļ”้āļĄāļēāļāļĄāļēāļĒ āļĢāļ§āļĄāļ—ั้āļ‡ script āļ•่āļēāļ‡āđ† āļ•āļēāļĄāļ—ี่āđ€āļĢāļēāļ•้āļ­āļ‡āļāļēāļĢ
........................................................................................................................................
āļ•ัāļ§āļ­āļĒ่āļēāļ‡āļāļēāļĢāļāļģāļŦāļ™āļ” crontab
---------------------------------
āļāļēāļĢāđ€āļžิ่āļĄ crontab āđ‚āļ”āļĒāđ€āļĢีāļĒāļāđƒāļŠ้āļ„āļģāļŠั่āļ‡ crontab -e āđ€āļĄื่āļ­ āđ€āļ‚้āļēāļŠู่āđ‚āļ›āļĢāđāļāļĢāļĄāđāļĨ้āļ§ āļāļ” i āđ€āļžื่āļ­āđ€āļžิ่āļĄ āļ„āļģāļŠั่āļ‡āļ”ัāļ‡āļ•ัāļ§āļ­āļĒ่āļēāļ‡āļ”้āļēāļ™āļĨ่āļēāļ‡āļ™ี้āđ€āļ‚้āļēāđ„āļ› āđāļĨ้āļ§āļ—āļģāļāļēāļĢāļšัāļ™āļ—ึāļāđāļĨ้āļ§āļ­āļ­āļāļĄāļēāđ‚āļ”āļĒāļāļ” Esc āđāļĨ้āļ§āļāļ” :wq!
Code:
0 12 * * * /etc/python.py
āļˆāļēāļāļ„āļģāļŠั่āļ‡āļ”้āļēāļ™āļšāļ™āļˆāļ°āđ€āļ›็āļ™āļāļēāļĢāļŠั่āļ‡āđƒāļŦ้āļĢัāļ™ script python.py āļ•āļ­āļ™ 12:00 āļ™. āļ‚āļ­āļ‡āļ—ุāļāđ†āļ§ัāļ™
Code:
0 12 * * 1 /root/wifilogs.py
āļˆāļēāļāļ„āļģāļŠั่āļ‡āļ”้āļēāļ™āļšāļ™ āļˆāļ°āļ—āļģāļāļēāļĢ Run script getlogs.pl āļ—ี่ path /home/tuxzilla āļ—ุāļāļ§ัāļ™āļˆัāļ™āļ—āļĢ์ āļ—ุāļāđ†āđ€āļ”ืāļ­āļ™ āļ•āļ­āļ™āđ€āļ—ี่āļĒāļ‡
Code:
0 0 * * 1,2 / root/wifilogs.py
āļ„āļģāļŠั่āļ‡āļ™ี้āđ€āļŦāļĄืāļ­āļ™āļ„āļģāļŠั่āļ‡āļ”้āļēāļ™āļšāļ™āļ„āļĢัāļš āđāļ•่āļˆāļ°āđ€āļžิ่āļĄāļāļēāļĢāļ—āļģāļ‡āļēāļ™āđƒāļ™āļ§ัāļ™āļ­ัāļ‡āļ„āļēāļĢāļ”้āļ§āļĒ āļ‹ึ่āļ‡āđ€āļĢāļēāļŠāļēāļĄāļēāļĢāļ–āđƒāļŠ้ "," āļ„ั่āļ™āđ„āļ›āđ€āļĢื่āļ­āļĒāđ†āđ„āļ”้ āđ€āļžื่āļ­āļ—ี่āļˆāļ°āļāļģāļŦāļ™āļ”āđ€āļžิ่āļĄāđƒāļŦ้āđāļ•่āļĨ่āļ° fields āļŦāļĢืāļ­āđƒāļŠ้ "*"
āđ€āļžื่āļ­āļāļēāļĢāļāļģāļŦāļ™āļ”āđ€āļ›็āļ™āļ—ั้āļ‡ āļŦāļĄāļ”(āļŦāļĄāļēāļĒāļ„āļ§āļēāļĄāļ§่āļē āļŦāļēāļāļ—ี่ field āļŠั่āļ§āđ‚āļĄāļ‡ āđ€āļ›็āļ™ * āļ็āļŦāļĄāļēāļĒāļ„āļ§āļēāļĄāļ§่āļēāļ•้āļ­āļ‡āļ—āļģāļ‡āļēāļ™āļ—ุāļāļŠั่āļ§āđ‚āļĄāļ‡)
āļ–ึāļ‡āļˆāļ°āļĄีāļŦāļĨāļēāļĒ user āđƒāļ™ āđ€āļ„āļĢื่āļ­āļ‡āđ€āļ”ีāļĒāļ§āļัāļ™āđāļ•่āļĒัāļ‡āđ„āļ‡ crontab āļ้āļĒ ัāļ‡āđ€āļ›็āļ™āļ‚āļ­āļ‡āđƒāļ„āļĢ āļ‚āļ­āļ‡āļĄัāļ™āđ„āļĄ่āļāļ§āļ™āļัāļ™āļ„āļĢัāļš āđāļĨāļ°āđ„āļĄ่āļŠāļēāļĄāļēāļĢāļ–āļ”ูāļ‚āļ­āļ‡āļัāļ™āđāļĨāļ°āļัāļ™āđ„āļ”้ āļ™āļ­āļāļˆāļēāļāđ€āļ›็āļ™ āļœู้āļ”ูāđāļĨāļĢāļ°āļšāļšāļ„āļĢัāļš āļ–ึāļ‡āļ•āļĢāļ‡āļ™ี้āđāļĨ้āļ§āļ็āļ„āļ‡āđ„āļĄ่āļĄีāļ­āļ°āđ„āļĢāļĒāļēāļāđ€āļิāļ™āļāļ§่āļēāđāļĨ้āļ§ āļŦāļēāļāđāļ•่āļ„āļ§āļēāļĄāļŠāļ°āļ”āļ§āļāđ€āļ—่āļēāļ™ั้āļ™āļ—ี่āļˆāļ°āļĄāļēāđāļ—āļ™āļ—ี āļŦāļĢืāļ­āđƒāļ„āļĢāļˆāļ°āđ€āļ­āļēāļĄāļēāđ€āļ›็āļ™āļ™āļēāļŽิāļāļē āļ­āļĒ่āļēāļ‡āļœāļĄāļ็āđ„āļĄ่āļ§่āļēāļ„āļĢัāļš

āļ—ี่āļĄāļē http://sabaylinux.blogspot.com/2009/07/crontab.html


Crontab – Quick Reference

Setting up cron jobs in Unix and Solaris
cron is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix , solaris.  Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times.
This document covers following aspects of Unix cron jobs
1. Crontab Restrictions
2. Crontab Commands
3. Crontab file – syntax
4. Crontab Example
5. Crontab Environment
6. Disable Email
7. Generate log file for crontab activity
1. Crontab Restrictions
You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use
crontab if your name does not appear in the file /usr/lib/cron/cron.deny.
If only cron.deny exists and is empty, all users can use crontab. If neither file exists, only the root user can use crontab. The allow/deny files consist of one user name per line.
2. Crontab Commands
export EDITOR=vi ;to specify a editor to open crontab file.
crontab -e    Edit your crontab file, or create one if it doesn’t already exist.
crontab -l      Display your crontab file.
crontab -r      Remove your crontab file.
crontab -v      Display the last time you edited your crontab file. (This option is only available on a few systems.)
3. Crontab file
Crontab syntax :
A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.
*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of        month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)
* in the value field above means all legal values as in braces for that column.
The value column can have a * or a list of elements separated by commas. An element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range).
Notes
A. ) Repeat pattern like /2 for every 2 minutes or /10 for every 10 minutes is not supported by all operating systems. If you try to use it and crontab complains it is probably not supported.
B.) The specification of days can be made in two fields: month day and weekday. If both are specified in an entry, they are cumulative meaning both of the entries will get executed .
4. Crontab Example
A line in crontab file like below removes the tmp files from /home/someuser/tmp each day at 6:30 PM.
30     18     *     *     *         rm /home/someuser/tmp/*
Changing the parameter values as below will cause this command to run at different time schedule below :
min hour day/month month day/week Execution time
30 0 1 1,6,12 * – 00:30 Hrs  on 1st of Jan, June & Dec.

0 20 * 10 1-5 –8.00 PM every weekday (Mon-Fri) only in Oct.

0 0 1,10,15 * * – midnight on 1st ,10th & 15th of month

5,10 0 10 * 1 – At 12.05,12.10 every Monday & on 10th of every month
:
Note : If you inadvertently enter the crontab command with no argument(s), do not attempt to get out with Control-d. This removes all entries in your crontab file. Instead, exit with Control-c.
5. Crontab Environment
cron invokes the command from the user’s HOME directory with the shell, (/usr/bin/sh).
cron supplies a default environment for every shell, defining:
HOME=user’s-home-directory
LOGNAME=user’s-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh
Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.
6. Disable Email
By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line .
>/dev/null 2>&1
7. Generate log file
To collect the cron execution execution log in a file :
30 18 * * * rm /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log

Monday, October 10, 2011

Install Ioncube on CentOS

I’ve seen many issues where Ioncube is required to be installed on a DA system. You can easily download and install it using the following steps;
Depending on your system OS/Platform select and download the loaders file which is compressed in different formats such as tar.gz, tar.bz2, zip. Make sure you select one which is of the recent date and of the latest version and extract it to /usr/local it will be extracted into the following directory;
/usr/local/ioncube
Once done you need to add a line to your php.ini. It can be located using the following command;
php -i | grep php.ini
Once you get the path, just edit it using your favorate editor (vi or pico) in my case it’s vi
vi /etc/php.ini
search for extension and below that add;
zend_extension = /usr/local/ioncube/ioncube_loader_lin_5.2.so
Don’t forget to restart your web server after that, once done you won’t be getting the same errors for Ioncube as earlier.

How To Install IonCube Loader on Centos

Go to http://www.ioncube.com/loaders.php
Download
wget http://downloads2.ioncube.com/loader_downloads/ioncube_loaders_lin_x86.tar.gz
tar xvfz ioncube_loaders_lin_x86.tar.gz
tar xvfz ioncube_loaders_lin_x86.tar.gz
cd ioncube
Copy loader-wizard.php to location you can access on a web browser.
I then get told that there is an updated script so I down load the latest and update it.
wget http://www.ioncube.com/loader-wizard/loader-wizard.tgz
tar xvfz loader-wizard.tgz
cp this file to a folder you can access from a browser.
Then follow the instructions;
mkdir /usr/local/ioncube
Copy the downloaded files to /usr/local/ioncube
cp * /usr/local/ioncube
cd /etc/php.d
Download ioncube.ini from from the link on loader-wizard.php page.
But the ioncube.ini in /etc/php.d
Restart you httpd server
service httpd restart
Click on the test link and make sure everything works
Then remove the loader-wizard.php from the folder that is browserable.

phpMyAdmin – Invalid hostname for server 2

If you have installed phpMyAdmin, you may get the errors
Invalid hostname for server 2. Please review your configuration.
Invalid hostname for server 3. Please review your configuration.
when you log in. If so, the solution is to comment out this block of code in config.inc.php (it appears twice) - just wrap it in '/*' and '*/' as I have below
PLAIN TEXT
PHP:
  1. /* This has been commented out because of error message
  2. $i++;
  3. $cfg['Servers'][$i]['host']            = '';
  4. $cfg['Servers'][$i]['port']            = '';
  5. $cfg['Servers'][$i]['socket']          = '';
  6. $cfg['Servers'][$i]['connect_type']    = 'tcp';
  7. $cfg['Servers'][$i]['extension']       = 'mysql';
  8. $cfg['Servers'][$i]['compress']        = FALSE;
  9. $cfg['Servers'][$i]['controluser']     = '';
  10. $cfg['Servers'][$i]['controlpass']     = '';
  11. $cfg['Servers'][$i]['auth_type']       = 'config';
  12. $cfg['Servers'][$i]['user']            = 'root';
  13. $cfg['Servers'][$i]['password']        = '';
  14. $cfg['Servers'][$i]['only_db']         = '';
  15. $cfg['Servers'][$i]['verbose']         = '';
  16. $cfg['Servers'][$i]['pmadb']           = ''; // 'phpmyadmin' - see scripts/create_tables.sql
  17. $cfg['Servers'][$i]['bookmarktable']   = ''; // 'pma_bookmark'
  18. $cfg['Servers'][$i]['relation']        = ''; // 'pma_relation'
  19. $cfg['Servers'][$i]['table_info']      = ''; // 'pma_table_info'
  20. $cfg['Servers'][$i]['table_coords']    = ''; // 'pma_table_coords'
  21. $cfg['Servers'][$i]['pdf_pages']       = ''; // 'pma_pdf_pages'
  22. $cfg['Servers'][$i]['column_info']     = ''; // 'pma_column_info'
  23. $cfg['Servers'][$i]['history']         = ''; // 'pma_history'
  24. $cfg['Servers'][$i]['verbose_check']   = TRUE;
  25. $cfg['Servers'][$i]['AllowDeny']['order']
  26.                                        = '';
  27. $cfg['Servers'][$i]['AllowDeny']['rules']
  28.                                        = array();
  29. */
Thanks! I was just upgrading our phpMyAdmin, and came across the same problem - your post was very helpful.

 
Design by GURU