środa, 11 lipca 2018

How to set up port forwarding with IP forwarding to vagrant VB box

I'm using Debian on host as well as guest but for other distributions configuration should be  the same and commands should be similar. I'm considering only Virtual Box guests.

First we need to configure private network on vagrant guest by adding following lines to Vagrantfile:

 config.vm.network "private_network", ip: "192.168.1.2"



This way vagrant will create additional host-only network for this box.
On the host there should be new network interface called vboxnet0 with ip 192.168.1.1. You can always list network interfaces with:

ifconfig

 I'm also asuming public IP of the host is 85.85.85.85 and is connected to eth0. Check your configurtion with ifconfig and adjust accordingly.
On the guest there should be additional network interface called eth1. Check your specific configurtion with ifconfig and adjust accordingly:

vagrant ssh
sudo ifconfig

 The problem with default (dhcp) configuration of port forwarding in vagrant boxes is that guests don't see clients IPs but only IP of the host (10.0.2.1). This is undesired then I'm running website and want to track users by IP. To configure IP forwarding along with port forwarding on private network (host-only) run these commands on host:


echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -A PREROUTING -t nat -i eth0 -d 85.85.85.85 -p tcp --dport 80 -j DNAT --to-destination 192.168.1.2:80
iptables -A FORWARD -p tcp -d 192.168.1.2 --dport 80 -j ACCEPT


I'm asuming port 80 need to be forwarded byt any port can be given. On guest you need to issue this command to allow backwards communication:


vagrant ssh
sudo route add default gw 192.168.1.1 eth1

Newtork configuration of this example can be illustrated on following picture:

środa, 4 października 2017

10 questions to check your knowledge of Object Oriented Language

  1. What's the difference between class and object?
  2. What can be put in class definition?
  3. Describe all access modifiers.
  4. What characterize static class?
  5. What's the difference between class field and static class field?
  6. What is a method signature?
  7. What is an interface and how do you implement interface?
  8. What is a default constructor?
  9. How to call constructor from another constructor? How to call base class constructor?
  10. How do you define constants?

poniedziałek, 29 maja 2017

How to configure Local Group Policy via PowerShell part 1


This is the 1st part of automatizng Local Group Policies.
In this post you will learn how to :

- Create new local users and groups
- Configure Local Group Policies


 Requirements :

- Windows PowerShell 4.0
- Microsoft .NET Framework 4






1.Creating Groups and Users

·         Download and install Carbon Powershell Module


 Remember to Unblock files

 

·         Start PowerShell ISE as administrator


Use this command for import Carbon module to Powerhsell

Set-ExecutionPolicy bypass -Force

Import-Module -Name PATH_TO_CARBON_MODULE\Import-Carbon.ps1


Examples of using the module

Create New User :
 

Install-User -UserName Dev -Password P@SS0W0RD -UserCannotChangePassword


Create New Group:

Install-Group -Name DevGroup -Description 'Dev'

Add User to Group:

Add-GroupMember -Name DevGroup -Member Dev
 

 

 

Remove Group Member :



Remove-GroupMember -Name Devgroup -Member Dev


More commands and informations here --> http://get-carbon.org/
 

2.Set Local Group Policies


·        Download PolicyFileEditor PowerShell Module by Dave Wyatt

 


 

·         Extract downloaded files on your computer and make sure that files are unblocked and name of module match name of Windows PowerShell Script Module file.

It’s important.



·         Now copy unblocked and prepared module here :
C:\Windows\System32\WindowsPowerShell\v1.0\Modules

 
·         Type this commands for Import and start using PolicyFileEditor module

Set-ExecutionPolicy bypass -Force

Import-Module -Name PolicyFileEditor



 
·       Now we have two ways to set Local Group Policy restrictions:

First way

Use Microsoft Management Console. Set whole configuration for computer and user manually. Then import all settings to .xml file which can be used multiple times for apllying this settings on another machines via PowerShell.

·         File/Add-Remove Snap-in…

Choose “Group Policy Object Editor” 

 
Local Computer :
 
 


Or/And Users




·         Now you can start setting Local Group Policy restrictions

 

 Save your settings.


Go to part 2 --->  http://blog.besharp.pl/2017/05/how-to-configure-local-group-policy-via_29.html
·