How do you know,
billvon?
Well, there are three parts to it:
1) Carbon dioxide and methane are greenhouse gases; they pass short wavelength light but block long wavelength infrared. You can demonstrate this in a high school chemistry lab with some simple equipment, so there's not much controversy there.
2) Increasing the concentration of greenhouse gases in a planet's atmosphere will warm a planet. We've seen extreme examples on Venus, which has a surface temperature hot enough to melt lead. Here on Earth we can observe the infrared we emit from the ground vs the amount that makes it into space, and can then calculate how much more heat we are retaining.
3) We are increasing the amount of CO2 in the atmosphere by burning fossil fuels, and we are releasing methane because in many cases it's a waste product from human projects (i.e. sewers, oil wells, landfills) We can easily calculate how much CO2 we release, for example, by calculating the amount of coal and oil we burn, and since we know the composition of those materials, we know how much carbon they contain (and thus how much carbon is released into the atmosphere.) We also know how much atmosphere there is. Using those two facts, we can calculate how much we are increasing CO2 concentrations every year. And in fact they have been rising year after year - from 280 ppm to over 400ppm today.
To validate all this, it would make sense to model it, then see if actual climate matches the model. To do this, the above three facts were fed into models as early as 1990, and predictions were made as to what would happen to global temperatures in the future. Those predictions have come very close to reality, thus validating the models.