Virtual Box – Different network connection

VirtualBox permette la connessione di una macchina virtuale a diversi tipi di rete locale. Vediamo nel dettaglio quali sono.

Le macchine virtuali sono fatte per collegarsi a differenti tipi di connessione LAN. In genere, in ambito domestico o delle piccole e medie imprese, vengono utilizzate solo per andare su Internet o far parte della rete locale. Per gli smanettoni o i tecnici, invece, può essere necessario creare una rete virtuale interna per effettuare esperimenti con i protocolli e le impostazioni. Insomma, c’è molta versatilità su questo aspetto. Ecco perché VirtualBox, offre diversi tipi di rete:

Network Address Translation (NAT)

Rete con NAT

Il servizio NAT è incluso in tutti i router/modem. Non fa altro che prendere tutte le connessioni dai vari computer e farle passare per una connessione unica, con un unico indirizzo IP. Perciò puoi avere una o più macchine virtuali che navigano su internet senza vedersi tra loro (ognuna di esse è in una rete isolata). In VirtualBox è la modalità predefinita e funziona con l’assegnazione di un DHCP al sistema operativo Guest.

Rete con NAT

Permette la creazione di una rete tra macchine virtuali, ma sempre con tecnologia NAT.

Bridged Networking (Scheda con bridge)

Rete con Bridge

Bridge in italiano si traduce letteralmente come “ponte”. VirtualBox fa, quindi, semplicemente da ponte tra la macchina virtuale e la rete locale. Dunque, la macchina Guest sarà collegata alla rete come qualsiasi altro computer fisico e potrà interfacciarsi con gli altri dispositivi in rete senza problemi. Ovviamente, dovrà essere configurato come un dispositivo fisico in rete (indirizzi IP, DNS, etc).

Rete Interna

Rete interna

VirtualBox permette di creare una rete interna, privata e non visibile dall’esterno. Ciò permette di avere dei server di prova con servizi come il DHCP, Active Directory, DNS, etc. Questa funzionalità garantisce il dialogo tra le macchine virtuali anche se l’Host non è collegato a nessuna rete. Infatti, le VM non possono dialogare tra loro in bridged se non c’è collegamento ad una vera rete. La “intnet”, invece, funziona sempre. Ovviamente in questo caso bisogna autoassegnarsi degli indirizzi o utilizzare un Server DHCP.

Host-only network (Scheda solo host)

Rete Host-Only

La rete di soli host è una rete interna in cui tutte le VM sono collegate tra loro (proprio come nella intnet), ma anche l’host è collegato ad essa. In questo caso vi è un’assegnazione di indirizzi IP data in automatico da VirtualBox stesso.

Il port forwarding

Port Forwarding

L’opzione NAT, come abbiamo già visto, permette ad una macchina virtuale di funzionare proprio come un computer connesso ad un router che esce su Internet. Se, però, volessimo inoltrare dei pacchetti ad una porta è possibile farlo. Un po’ come quando si aprono le porte sul router (ad esempio la 80) e si può accedere al server web tramite l’Indirizzo IP pubblico. Solo che, in questo caso, accedendo all’indirizzo host (ad es. 192.168.1.100:80) avremo un forwarding alla porta 80 della macchina virtuale.

Regole di inoltro delle porte

Managing The Postfix Queue

In this article, I will go over the tools Postfix offers you to manage the mail queue. There are 6 actions you can perform on messages in the queue.

  • List messages.
  • Delete messages.
  • Hold messages.
  • Re-queue messages.
  • Display the contents of messages.
  • Flush the messages in the queue.

Listing Messages in the Postfix Queue

Postfix provides a tool called postqueue. The command provided with the -p switch will display an entry for each message in the queue. The output will include a column for the message IDsizearrival timesend, and recipient addresses.

Messages that are currently in the active queue will display a asterisk to the right of the message ID.

If there is a message in the hold queue, it will display a exclamation point to the right of the message ID.

If a message is deferred, there will not be symbol / mark to the right of the message ID.

postqueue -p

-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------  
5866DAC07F3 362 Sat Oct 12 15:53:56 trankin@tullyr.com  
(connect to mail.tullyr.com[208.70.75.100]:25: Connection refused)  
<trankin@tullyr.com>

Deleting Messages in the Postfix Queue

To delete messages from the Postfix queue, you can use the postsuper command. The postsuper tool can be used to delete a single message, or all messages in the queue.

To delete a single message from the queue, provide the -d switch followed by the message ID.

postsuper -d 5866DAC07F3

When you want to delete all messages in the queue, you provide postsuper with the word ALL in all capitals instead of the message ID.

postsuper -d ALL

NOTE – Be careful when using the postsuper command with the -d ALL switch. This command will delete all messages in the queue immediately without prompting you for verification.

Holding Messages in the Postfix Queue

The Postfix hold queue provides a place for messages to be held indefinitely. If you move a message into the hold queue, it will not be delivered until you specifically remove it or move it back into the normal queue processing.

To place a message in the hold queue, you use the tool postsuper with the -h switch followed by message ID.

postsuper -h 5866DAC07F3

When you need to move a messae back into the normal queue for processing, you use the postsuper command with the -H switch followed by the message ID.

postsuper -H 5866DAC07F3

Re-queue Messages in the Postfix Queue

If you have messages that are incorrect based on a misconfigured Postfix installation, you may need to re-queue the messages via the postsuper command. Some example of bad messages could be problems such as incorrect transport typeincorrect rewriting of an address, or an incorrect next hop.

After fixing the Postfix configuration, you can re-queue a single message or all messages. To requeue a message, you will use the postsuper command with the -r switch. When this command is run, it will update the incorrect information based on the new configuration.

To re-queue a single message you pass the message ID as in the example below.

postsuper -r 5866DAC07F3

If you need to re-queue all messages, you can pass the capital word ALL.

postsuper -r ALL

Displaying the Contents of Messages in the Postfix Queue

If you need to view the contents of a message in the queue, Postfix provides the postcat tool for this. The postcat tool will display the contents of a file when provided with the -q switch followed by the message ID.

postcat -q 5866DAC07F3

Flushing Messages in the Postfix Queue

If you have messages in the queue that you would like to flush, you can use the postqueue command with the -f switch. Flushing the queue will cause Postfix to attempt to deliver all messages in the queue immediately.

postqueue -f

There are times when this is needed. However, it’s usually not a good idea to flush all of the messages in the queue. If you do this a lot, it can have an impact on the performance on your mail server. You should leave the queue management to the Postfix queue manager.

With Postfix, it’s possible to flush only those messages that are going to a specific domain. You can do this with the -s switch provided by postqueue. However, to do this the domain must be eligible for fast flush.

For a domain to be eligible for fast flush, it must be listed in the fast_flush_domains parameter. In Postfix, the default value for the fast_flush_domains includes all of the hosts that are listed in relay_domains.

To add the site to the fast_flush_domains you can append it to the line fast_flush_domains as shown below:

fast_flush_domains = $relay_domains tullyrankin.com

Now if you want to flush mail that is destined for the domain you added to the fast_flush_domains, you can use the postqueue command with the -s option as shown below:

postqueue -s tullyrankin.com

Upload your images at scale

For the best performance, you should always upload your images at scale if possible. For example, if you have an image that you want to display at 200 px wide, don’t upload an image that is 400 px wide and then scale it with HTML. A better way to accomplish this is to use the srcset attribute in the <img> tag which allows you to define possible resolutions that the browser can choose from. Here an example:

<img srcset="/img/keycdn-300.jpg 300w,
             /img/keycdn-600.jpg 600w,
             /img/keycdn-1200.jpg 1200w"
     src="/img/keycdn-600.jpg" alt="KeyCDN">

Most modern web browsers support srcset, except IE and opera mini.

Regular Expression

wiki page

Regular expression is a sequence of character(s) mainly used to find and replace patterns in a string or file.
So we can say that the task of searching and extracting is so common that Python has a very powerful library called regular expressions that handles many of these tasks quite elegantly.

SYMBOL USAGE
$ Matches the end of the line
\s Matches whitespace
\S Matches any non-whitespace character
* Repeats a character zero or more times
\S Matches any non-whitespace character
*? Repeats a character zero or more times (non-greedy)
+ Repeats a character one or more times
+? Repeats a character one or more times (non-greedy)
[aeiou] Matches a single character in the listed set
[^XYZ] Matches a single character not in the listed set
[a-z0-9] The set of characters can include a range
( Indicates where string extraction is to start
) Indicates where string extraction is to end

website to check regular expression