Professional Documents
Culture Documents
# /etc/init.d/bind9 restart
DNS server, gets the response back and then needed to initialise the cache of internet domain [....] Stopping domain name service...:
caches the results. name servers. You can manually generate it by bind9waiting for pid 24713 to die
It is not possible to find out from a query result running the following command: . ok
whether it was answered from a zone master or [ ok ] Starting domain name service...:
from a slave. $ dig @a.root-servers.net . NS > db.root bind9.
14 Access control
lists (ACL)
which checks the syntactical validity of your
configuration. If there are no syntax errors
in your current configuration, you will get no
output. No tool can catch logical DNS errors.
“All log messages from BIND are 16 Test the cache DNS server
In order to test your DNS server, try
on your LAN, you should put the IP of the caching define a new access control list:
server in the /etc/resolv.conf file and comment
out all other DNS servers. However, this can be acl OTENET {
dangerous because if the caching DNS server 2.86/16;
stops working for some reason, your network will localhost;
not be able to operate normally. localnets;
};
produce a large amount of log messages, so you help you to check the correctness of your # rndc dumpdb -all
might decide that you want to decrease the log current configuration. These tools include # ls -l /var/cache/bind/named_dump.db
level using rndc after making sure that your DNS named-checkconf, named-checkzone and -rw-r--r-- 1 bind bind 9446 Oct 15 11:15
server works without any problems. named-compilezone. /var/cache/bind/named_dump.db
Program a
client-server
application
Each operating system provides its own set
of networking APIs, but Qt gives a solution
to simplify creating chatty applications
Modern computer networks are composed Our finger exercise-level applications don’t
of multiple protocols. Creating well-formed require this level of sophistication. It will
packets by hand is almost impossible – the suffice to begin by creating a command line
protocol stack and its underlying network project called ImagineTCPServer. Qt Creator
hardware affect the format. does not add the networking module to newly
Engineers working on Unix solved this problem created applications. This can easily be
by introducing an abstraction layer – so-called remedied by opening its .pro file and adjusting
sockets acting as endpoints between two the QT directive so that network gets included
local or remote applications. Developers use at compile time:
the standardised interface in order to provide
commands to the socket, which are then QT += network
translated to the network.
When dealing with sockets, a basic With that, it is time to create the server object.
understanding of networking is beneficial. For Its declaration can be placed inside the main()
now, it shall suffice to define that messages function responsible for program bring-up:
can be transmitted by two high-level protocols.
TCP – short for Transmission Control Protocol myServer=new QTcpServer();
– provides confirmation when data has been if(myServer->listen(QHostAddress::Any,102
delivered successfully. This is accomplished by 5)==false)
a relatively complex sequence of packets which {
add overhead to the communication process. qDebug() << “Server error” <<
However, some applications don’t require this. myServer->serverError();
For them, UDP provides a sleeker communication return 0;
protocol that forgoes delivery confirmation. On }
a network, computers are identified by their IP else
address. Individual services are then identified by {
their port numbers – consider them apartment qDebug() << “Server up” <<
door numbers inside a high-rise building. myServer->serverAddress() << “ ” <<
Developers working on communication myServer->serverPort();
software tend to face a chicken-egg situation }
– if no server has been written, the client can’t
connect. On the other hand, the lack of a client In classic Berkeley socket programming, server
means that the server can’t be tested. and client logic are handled by instances of the
In practical projects you should start out by socket class. Qt provides a dedicated server
creating a rough mock-up of the messages that that contains helper methods for connectivity
the client and server will exchange. You don’t management. After start-up, we invoke the
need to get this 100 per cent right on the first try; listen() method in order to make our QTcpServer
most protocols change as they get implemented. wait for incoming connections.
TCP/IP to connect
representing the connection to the selected to issues once more than one client is connected
client. We’ll wire its disconnected signal to the – we connect all signals to one slot which makes
the processes
deleteLater slot to ensure unneeded sockets will keeping the different connections apart difficult.
be eliminated automatically. In the next step a A thread is a convenient solution for this
sounds like
byte array is populated and sent to the client. problem. Threads are subroutines that run in
Qt’s underlying DataStream class gets parallel to the main application code – spawning
programs are
later versions of Qt can interpret the data adding a new class whose header looks like this:
provided in the socket. Many applications use
implemented in
Qt 4.0’s format. If your program is limited to Qt 5 class ImagineThread:public QThread
and above due to other dependencies, you can {
this fashion”
also define this version as baseline. Q_OBJECT
The next step involves modifications public:
to the client. Insert a class similar to the ImagineThread(QTcpSocket* _aSocket);
Connecting to servers requires the use of a ImagineListener to handle the signals emitted void run();
QTcpSocket. Its most basic implementation is from the socket class. Our application has to public:
made up of but two lines: deal with three events – we need to notify the QTcpSocket* mySocket;
user of successful and failed connections and };
QTcpSocket *mySocket; must receive data sent from the server.
int main(int argc, char *argv[]) Status messages are handled by emitting the The actual payload can be found in the
{ corresponding statements to the console via run() method which will be executed in the
QCoreApplication a(argc, argv); qDebug() (see Fig 02). background after the thread was spawned:
mySocket=new QTcpSocket(); Receiving data is more complex. Our simple
mySocket->connectToHost(QHostAddress protocol doesn’t inform the client in advance void ImagineThread::run()
::LocalHost, 1025); about how much data is to be transmitted. Due {
return a.exec(); to that, we simply read whatever amount of data exec(); //Start event loop
} has been received: }
void ImagineThread::dataReady()
ConnectToHost() is another asynchronous void ImagineReceiver::dataReady() {
method which takes two parameters. The first { QDataStream in(mySocket);
one designates the IP to use, while the second QDataStream in(mySocket); in.setVersion(QDataStream::Qt_4_0);
specifies the port. Successful connections in.setVersion(QDataStream::Qt_4_0); QString thatsIt;
will be indicated by the emission of a signal QString thatsIt; in >> thatsIt;
which we will handle in the next step. For now, in >> thatsIt; qDebug() << thatsIt;
a running instance of ImagineTCPServer will exit();
display a connection attempted message when qDebug() << thatsIt; }
our client is started. } ImagineThread’s sole role involves staying until
At the first glance, using TCP/IP to connect a signal is emitted. We accomplish that by
two processes on the same machine sounds Each of the slots must be connected to invoking the exec() method which creates an
like overkill. However, many programs are the socket. This should be done before the event loop. It keeps idling until exit is called from
implemented in this fashion – handling inter- connectToHost method is invoked. On some the dataReady handler.
process communication via sockets provides a operating systems the connected signal is Our server must be modified in order to
safe and simple way to de-couple components emitted before connectToHost returns (Fig. 03). start the thread when a new client connects
from one another. Run the program in its current state to display (Fig. 04).A classic beginner’s mistake involves
“Multithreaded
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
programs can
out << QString(“Hello, client!”);
clientConnection->write(block);
behave oddly”
}
“Default Netcat
behaviour is similar
to a simulated
network interaction”
03 Netcat as a client
The most common Netcat usage is acting as a client
for a server process. This is mostly used for troubleshooting
network servers because you can see the raw data of the
full interaction. The following command will interact with
an SMTP server:
06 The UDP protocol
By default, all Netcat interactions work with the
TCP protocol. However, it’s also possible to use the UDP
Above You can see
details on the Netcat
package right at the
protocol that is specified with the use of the -u option. This top of this output
$ nc linode 25 is particularly valuable because Telnet can only test TCP
services. The following command tries to test a DNS server
As you can guess, you can give either the host name or the IP that uses UDP:
address of the remote host. Finding
$ netcat -vv -u 8.8.8.8 53 the problem
04 Use files for input and output
According to Unix philosophy, the input to a program
can be read from a file and the output can be captured into
You can create a UDP server if you combine the -l option with
the -u option.
As you already know,
there are many
tools that can be
a file. The input is defined as <filename and the output as used for network
>filename. You can also use Unix pipes to get your input from troubleshooting,
the output of other processes. including netstat,
traceroute, wget,
ping, lost, nmap,
telnet, etc. If you
cannot find and
solve the problem
05 Netcat as a server
Not only you can use Netcat as a client, you can also
07 Use Netcat for port scanning
Netcat can be used for port scanning as a naive
version of Nmap. The next command scans the 192.168.2.1
you are experiencing
using this software,
you should always
have in mind that
use it for creating a server! The next command makes Netcat IP address using a range of port numbers from 20 to 40: an erroneous
listen to port number 1234 for incoming TCP connections: network device can
$ netcat -z -v -n 192.168.2.1 20-40 sometimes cause
$ netcat -l 1234 strange networking
The -z option tells Netcat to send zero data. In other words, problems, so you
might need to start
The job is done by the -l option because it tells Netcat to listen Netcat closes the connection as soon as it opens it, without
looking at your
for incoming connections. The port number is also provided in any actual data exchange taking place. The -n option tells hardware instead.
the command line. Netcat to disable DNS lookup for the given IP address.
08 File transfer
Netcat can also do things that other similar utilities
can’t do at all. One of those rare things is file transferring.
11 Verbose output
Netcat can generate richer output to help you when
troubleshooting. You should use the -v command line
First, you should start the server part as follows: parameter to make Netcat give more verbose output. Using
-vv instead of just -v gives a larger amount of verbose output,
$ cat fileToTransfer | nc -l 4567 which is very useful.
As you can see, you should choose the file that you want to
transfer in advance.
“Firewalls and routers can make 12 Troubleshoot a web server The HTTP service is just a TCP service, so Netcat can
Netcat misbehave when used for be used to get data from a web server. This command initiates
a connection to a web server:
Using the bc utility, you can find out that the network speed is
about 1,108,087 bytes per second, which is absolutely perfect
for a 10MB wireless network.
02 Format a
partition
02 Format a partition
Now the tools are installed, you can set
05 Grab your file system details
Just in case you’ve forgotten, you can
always check the details of your btrfs partitions
07 Make a subvolume
You can create subvolumes within btrfs
that can have different mount options and
up your btrfs partition on your system using and hard drives. This also works with individual mount points, and only uses space when they
gparted if you want. Launch it and navigate to hard drives in an array, which is why we mentioned need it. Create one in the terminal using:
the device that you want to format. You can either RAID in the previous step. In a terminal, use:
reformat existing partitions or make a smaller $ btrfs subvolume create btrfs/
btrfs partition instead. $ btrfs file system show /dev/sda subvolume1