Linux – Network – Technology
Posts tagged linux
Plesk – Scripting
May 17th
Add DNS
/usr/local/psa/bin/dns.sh -a DOMAIN -mx "" -mailexchanger "DNS" -priority PRIORITY
Delete DNS
/usr/local/psa/bin/dns.sh -d DOMAIN -mx "" -mailexchanger "DNS" -priority PRIORITY
Disable mail for all domains
#!/bin/bash
# This script finds all sites that have the mail service on - and then it turns it off.
SiteList=`egrep 'Server(Name)' /var/www/vhosts/*/conf/httpd.include|awk '{print $3}'|grep -v www.*|grep -v '^.*\..*\..*$'|sed 's/:80//'|sed 's/:443//'|sort -u`;
for Site in $SiteList
do
Result=`/usr/local/psa/bin/domain -i $Site | grep 'Mail service' | awk '{print $3}'`;
if [ $Result == On ]; then
Command=`/usr/local/psa/bin/domain -u $Site -mail_service false`
echo "Turning Off Mail Service: $Site";
fi
done
Add Dns sec in OVH
#!/usr/bin/python
import pprint
import sys
import getopt
from SOAPpy import WSDL
soap = WSDL.Proxy('https://www.ovh.com/soapi/soapi-re-1.11.wsdl')
DOMAIN = sys.argv[1]
#login
session = soap.login('xxxxx-ovh', '*****password*****', 'fr', 0)
print "login successfull"
#dedicatedSecondaryDNSAdd
soap.dedicatedSecondaryDNSAdd(session, 'ns*****.ovh.net', '*****IP*******', DOMAIN, 'sdns1.ovh.net', '213.251.188.140')
print "dedicatedSecondaryDNSAdd successfull"
#logout
soap.logout(session)
print "logout successfull"
Pulls email password out of Plesk database for given email address
SELECT concat(mail_name,'@',domains.name) as email,password,redirect,redir_addr,autoresponder,spamfilter,virusfilter,alias FROM mail LEFT JOIN domains ON mail.dom_id=domains.id LEFT JOIN accounts ON mail.account_id=accounts.id LEFT JOIN mail_aliases ON mail_aliases.mn_id = mail.id WHERE domains.name = '*******DOMAIN******'
Recovery all mail accounts
/usr/local/psa/admin/sbin/mchk --without-spam
Add SPF records to all domains
mysql -u admin -p`cat /etc/psa/.psa.shadow` psa -e "select dns_zone_id,displayHost from dns_recs GROUP BY dns_zone_id ORDER BY dns_zone_id ASC;" | awk '{print "INSERT INTO dns_recs (type,host,val,time_stamp,dns_zone_id,displayHost,displayVal) VALUES ('\TXT'\,'\"$2"'\,'\v=spf1 a mx ~all'\,NOW(),"$1",'\"$2"'\,'\v=spf1 a mx ~all'\);"}' | mysql -u admin -p`cat /etc/psa/.psa.shado
Squid
May 17th
Squid en High Anonymous
forwarded_for off header_access Allow allow all header_access Authorization allow all header_access Cache-Control allow all header_access Content-Encoding allow all header_access Content-Length allow all header_access Content-Type allow all header_access Date allow all header_access Expires allow all header_access Host allow all header_access If-Modified-Since allow all header_access Last-Modified allow all header_access Location allow all header_access Pragma allow all header_access Accept allow all header_access Accept-Encoding allow all header_access Accept-Language allow all header_access Content-Language allow all header_access Mime-Version allow all header_access Cookie allow all header_access Set_Cookie allow all header_access Retry-After allow all header_access Title allow all header_access Connection allow all header_access Proxy-Connection allow all header_access All deny all
Reload Squid
squid -k reconfigure
Logformat
logformat squid %tl %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt
Open Gtalk and MSN
# Permit Google Talk acl GTALK_ports port 5222 5050 acl GTALK_domains dstdomain .google.com acl GTALK_hosts dstdomain talk.google.com acl GTALK_methods method CONNECT # http_access allow GTALK_methods GTALK_ports GTALK_hosts http_access allow GTALK_methods GTALK_ports GTALK_domains # Permit MSN acl MSN_ports port 1863 443 1503 acl MSN_domains dstdomain .microsoft.com .hotmail.com .live.com .msft.net .msn.com .passport.com acl MSN_hosts dstdomain messenger.hotmail.com acl MSN_nets dst 207.46.111.0/255.255.255.0 acl MSN_methods method CONNECT # http_access allow MSN_methods MSN_ports MSN_hosts http_access allow MSN_methods MSN_ports MSN_domains http_access allow MSN_methods MSN_ports MSN_nets http_access deny !Safe_ports !GTALK_ports !MSN_ports
Tips & Tricks
No cache for domain
acl NOCACHEDOMAIN dstdomain www.redhat.com no_cache deny NOCACHEDOMAIN
Linux – NFS Client/Server
May 17th
Server
apt-get install nfs-kernel-server nfs-common portmap
Config
vi /etc/exports # For Full Read Write Permissions allowing any computer from 192.168.1.1 through 192.168.1.255 /files 192.168.1.1/24(rw,no_root_squash,async) # Read only /files 192.168.1.2 (ro,async)
If you make changes to /etc/exports on a running NFS server, you can make these changes effective by issuing the command
exportfs -a
Client
apt-get install portmap nfs-common
This will install all the required packages for nfs client
Mounting manually
Example to mount server.mydomain.com:/files to /files. In this example server.mydomain.com is the name of the server containing the nfs share, and files is the name of the share on the nfs server
The mount point /files must first exist on the client machine.
Create files directory using the following command
mkdir mount_point
You need to mount the share using the following command
mount server.mydomain.com:/files /files
Now you may need to restart services using the following command
/etc/init.d/portmap restart /etc/init.d/nfs-common restart
Mount in fstab
server.mydomain.com:/files /files nfs rsize=8192,wsize=8192,timeo=14,intr
Linux – trick
May 17th
Bash color
-
\e[ - Start color scheme
-
\e[m - Stop color scheme
-
\u - Username. The original prompt also has \h, which prints the host name.
-
x;y - Color pair to use (x;y)
-
$PS1 - is your shell prompt
-
\w - Current absolute path. Use \W for current relative path
-
\t -the current time in 24-hour HH:MM:SS format
vi ~/.bashrc export PS1="\e[4;32m[\t - \u@\h \w]\$ \e[m “
Bash shell shortcuts
CTRL - Key bound
| Key | Description |
|---|---|
| CRTL + a | Start line |
| CTRL + e | End line |
| CTRL + u | Delete backward from cursor |
| CTRL + d | Delete character under the cursor |
| CTRL + h | Delete character before the cursor |
| CTRL + y | Paste |
ALT - Key bound
| Key | Description |
|---|---|
| ALT + c | Capitalize word |
| ALT + l | Lowercase |
| ALT + e | Delete word |
Iptables - Rewrite ip for output
Une des solution consiste à réécrire tous les paquets sortant en leur réattribuant votre adresse IP failover. Pour ceci, nous allons utiliser le flux SNAT de Iptables (Source NAT).
Commençons par écire une règle de réécriture des paquet (nous supposons que l'interface réseau est eth0, que votre IP physique est 21.22.23.24 et que votre IP failover est 13.14.15.16):
/sbin/iptables -t nat -A POSTROUTING -o eth0 -s 21.22.23.24 -j SNAT --to 13.14.15.16
Kill TCP connexion
-
Kill on connexion on port 21
tcpkill -i eth0 port 21
-
Kill all connexion (in/out) on host
tcpkill host 192.168.1.2
How to fix your Windows MBR with an Ubuntu liveCD
May 12th
You need to install ms-sys for ubunut
Edit the source list and add
vi /etc/apt/sources.list deb http://ubuntu.mirror.cambrium.nl/ubuntu/ dapper main universe
Update and install
apt-get update apt-get install ms-sys ms-sys -m /dev/sda
Dovecote
May 10th
Master account
Il est parfois utile de pouvoir se connecter sur une des boites mails hébergées sans connaître son mot de passe pour diverses raisons:
-
via un script pour analyser d’éventuels mails identifiés comme spam/ham par l’utilisateur;
-
via un script pour archiver des emails anciens;
-
directement afin de reproduire un bug signalé par l’utilisateur.
Il est évident que cette technique ne peut être utilisée simplement pour consulter les emails des utilisateurs à leur insu; c’est une atteinte à la vie privée qui peut être poursuivie par les tribunaux. Vous êtes donc prévenu, et comme pour tous les articles de ce blog, vous mettez ce qui suit en oeuvre sous votre entière responsabilité et en assumez pleinement les éventuelles conséquences.
Cette mise en garde étant faite, le concept est donc de définir un couple login/mot de passe ayant accès à toutes les boites mails hébergées sur votre serveur. Cet utilisateur master n’a rien à voir avec les utilisateurs mail déjà existants.
Dans le fichier /etc/dovecot/dovecot.conf, rajoutez la directive auth_master_user_separator=*. Puis, recherchez la section auth default et complétez-la pour qu’elle ressemble à ce qui suit:
auth_default {
passdb passwd-file {
args = /etc/dovecot/passwd.masterusers
master = yes
}
}
Le fichier /etc/dovecot/passwd.masterusers est de type htaccess. Voici les commandes pour le générer:
touch /etc/dovecot/passwd.masterusers htpasswd -s /etc/dovecto/passwd.masterusers admin
Vous donnez alors le mot de passe de l’utilisateur admin. Vous pouvez répeter la dernière ligne autant de fois que désiré avec d’autres noms d’utilisateurs. Les utilisateurs master pourront alors se connecter au moyen de adresse@domaine.com*admin et du mot de passe associé au compte admin.
Configuration d’un tunnel VPN IPSEC en mode transport
May 10th
Pour que les échanges d’information réseau entre les deux serveurs dédiés soient un minimum sécurisé (comprendre difficilement “sniffable”), j’ai décider de monter un tunnel VPN en IPSEC entre les deux.
Les serveurs sont sous Debian Etch. (vous adapter si vous avez un autre OS)
IPSEC autorise 2 modes de communication le mode tunnel (1 serveur/réseau vers 1 réseau) et le mode Transport (1 serveur vers 1 serveur) (en résumé hein, venez pas me saouler avec mon simplicisme
)
apt-get install ipsec-tools
on se configure le /etc/ipsec-tools.conf sur les deux serveurs. ns11111
#!/usr/sbin/setkey -f
flush;
spdflush;
# AH
add 192.168.20.30 192.168.20.20 ah 15700 -A hmac-md5 "1234567890123456";
add 192.168.20.20 192.168.20.30 ah 24500 -A hmac-md5 "1234567890123456";
# ESP
add 192.168.20.30 192.168.20.20 esp 15701 -E 3des-cbc "123456789012123456789012";
add 192.168.20.20 192.168.20.30 esp 24501 -E 3des-cbc "123456789012123456789012";
spdadd 192.168.20.20 192.168.20.30 any -P out ipsec
esp/transport//require
ah/transport//require;
spdadd 192.168.20.30 192.168.20.20 any -P in ipsec
esp/transport//require
ah/transport//require;
ns22222
#!/usr/sbin/setkey -f
flush;
spdflush;
# AH
add 192.168.20.30 192.168.20.20 ah 15700 -A hmac-md5 "1234567890123456";
add 192.168.20.20 192.168.20.30 ah 24500 -A hmac-md5 "1234567890123456";
# ESP
add 192.168.20.30 192.168.20.20 esp 15701 -E 3des-cbc "123456789012123456789012";
add 192.168.20.20 192.168.20.30 esp 24501 -E 3des-cbc "123456789012123456789012";
spdadd 192.168.20.30 192.168.20.20 any -P out ipsec
esp/transport//require
ah/transport//require;
spdadd 192.168.20.20 192.168.20.30 any -P in ipsec
esp/transport//require
ah/transport//require;
Génération des clés
Il faut bien évidemment générer vos propres clés, à savoir les zones commençant pas 0x. les 2 premières étant des clés de 128 bits, il faut y mettre 32 octets hexadecimaux, et 48 pour les clés 3des-cbc.
Le plus simple pour obtenir ces clés aléatoirement est de se baser sur le périphérique /dev/urandom de votre machine, en procédant ainsi :
-
Affiche 32 caractères hexadécimaux aléatoires :
hexdump -e '8/2 "%04x" ' /dev/urandom -n 16; echo
-
Affiche 48 caractères hexadécimaux aléatoires :
hexdump -e '8/2 "%04x" ' /dev/urandom -n 24; echo
Postfix – Specify output ip per domain
May 10th
We have to use de function sender_dependent_default_transport_maps.
-
Edit a new file
vi sdd_transport_maps.regexp /@opilab\.ch$/ opilab_ch: /@opilab\.com$/ opilab.com:
-
Edit master.conf
vi /etc/postfix/master.conf
opilab_ch unix - - n - - smtp
-o smtp_bind_address=IP1
-o smtp_helo_name=opilab.ch
-o syslog_name=postfix-opilab_ch
opilab_com unix - - n - - smtp
-o smtp_bind_address=IP2
-o smtp_helo_name=opilab.com
-o syslog_name=postfix-opilab_com
-
Edit main config
vi /etc/postfix/main.cf sender_dependent_default_transport_maps = regexp:/etc/postfix/sdd_transport_maps.regexp
Uncompress bzroot
May 10th
This is the hard way to do it, but here’s what I ended up doing:
-
shutdown unraid server
-
move the flash drive to my linux box and mount
-
copy bzroot from flash drive to my linux box
-
uncompress bzroot:
zcat bzroot | cpio -i -d -H newc –no-absolute-filenames
-
moved bzroot file out of the way (ie mv bzroot ..)
-
made edits to /etc/samba/smb.conf:
# misc
host msdfs = No msdfs root = No
-
do anything else you want to do that needs to remain persistent across reboots here
-
recompress bzroot:
find . | cpio -o -H newc | gzip > bzroot
-
copy new bzroot to flash drive
-
stick the flashdrive back in the unraid server and boot
That’ll permanently edit the config file.