search

Friday, May 22, 2015

How to configure dnsmasq to forward all requests to specific address

For example you have a virtual machine, which you use for local development, and you want all requests to the sitesupport.net (name of the website that you are developing) forwarded to the virtual machine. We will use dnsmasq to achieve it.

Install dnsmasq:
sudo yum install dnsmasq


Start it with command:
sudo service dnsmasq start


Check if it was started without any errors:
sudo service dnsmasq status


If there is an error that dnsmasq failed to start because port 53 is already in use, you can check what process listening this post with command:
sudo netstat -tulpn | grep :53


If the process is dnsmasq itself it probably means that you have libvirt installed that has its own dnsmasq copy. To resolve that conflict we need to configure dnsmasq. Configuration file we are going to store in /etc/dnsmasq.d/vm.conf. By default dnsmasq uses file /etc/dnsmasq.conf for configuration. If you open that file, you will be able to see lots of examples and configuration descriptions. Lets left this file intact (almost) and allow dnsmasq to extent configuration with files from dnsmasq.d directory by adding (uncommenting) line:
# Include all files in a directory which end in .conf
conf-dir=/etc/dnsmasq.d/,*.conf


Now create file /etc/dnsmasq.d/vm.conf with the following content:
interface=lo
bind-interfaces
address=/sitesupport.net/192.168.33.10


The first line determines what interface dnsmasq will be listening. To check all available interfaces use command ifconfig.


Basicly you need to listen to localhost or 127.0.0.1. You can probably do it with:
listen-address=127.0.0.1


The last line of the configuration file says that all requests to sitesupport.net (including subdomains, like super.sitesupport.net) will be redirected to 192.168.33.10 (that's my virtual machine).

Also you need to add to the file /etc/dhcp/dhclient.conf (or create the file if it does not exist):
prepend domain-name-servers 127.0.0.1;


You also need to restart your system. Instead of restarting the system you may try to restart following services:
sudo service dnsmasq restart
sudo service NetworkManager restart


To check that everything works correctly, use command:
ping sitesupport.net

The output should show that the request was redirected to 192.168.33.10.

Thursday, May 21, 2015

vagrant: How to automatically update Guest Additions

To autmatically update Guest Additions on your vagrant machine you need to install vagrant-vbguest plugin. From the folder with Vagrantfile run the command:
vagrant plugin install vagrant-vbguest

Next time you start it with vagrant up, Guest Additions will be updated

Wednesday, May 20, 2015

fedora 21: How to add and preserve DNS server

Normally NetworkManager handels all DNS configuration. Every time when new network connection was established (?) it regenerates file /etc/resolv.conf which contains DNS server data, so editing this file is useless.

To add DNS server on top of the DNS servers list from your connections you need to create or edit file /etc/dhcp/dhclient.conf and add the following line:
prepend domain-name-servers 192.168.33.10;

Where 192.168.33.10 is address of DNS server.

After applying changes you need to reboot or restart NetworkManager service:
sudo service NetworkManager restart


Tuesday, May 19, 2015

fedora 21: How to mount remote filesystem via SSH

If you use vagrant for development you might need an access to the filesystem of the virtual machine. There is a way to mount a folder from your virtual machine to your local machine so you will be able to open and edit with your favourite code editor.

First step is to install fuse-sshfs package:
sudo yum install fuse-sshfs


Then you can mount folder from the virtual machine with command:
sshfs -o idmap=user vagrant@192.168.33.10:/home/vagrant /home/jsn/vagrant/vm

The first path is the path inside the virtual machine and the second one is for local machine.